JSFiddle - React, Tailwind, and code Playground
by Kabeer Rifaye
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
JavaScript
var res = [{
"data": {
"hits": {
"total": 804251,
"max_score": null,
"hits": [{
"_source": {
"bps": 1
}
}, {
"_source": {
"bps": 2
}
}, {
"_source": {
"bps": 3
}
}]
}
}
}, {
"data": {
"hits": {
"total": 804251,
"max_score": null,
"hits": [{
"_source": {
"bps": 1
}
}, {
"_source": {
"bps": 2
}
}, {
"_source": {
"bps": 3
}
}]
}
}
}, {
"data": {
"hits": {
"total": 804251,
"max_score": null,
"hits": [{
"_source": {
"bps": 1
}
}, {
"_source": {
"bps": 2
}
}, {
"_source": {
"bps": 3
}
}]
}
}
}, {
"data": {
"hits": {
"total": 804251,
"max_score": null,
"hits": [{
"_source": {
"bps": 1
}
}, {
"_source": {
"bps": 2
}
}, {
"_source": {
"bps": 3
}
}]
}
}
}];
var arr = [];
_.map(res, function(d) {
var data = d.data.hits.hits;
_.map(data, function(dd,i) {
arr[i] = (arr[i] != undefined && arr[i] != "" ? arr[i] : 0) + parseInt(dd._source.bps);
});
});
console.log(arr);