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 = [{
"id": 1,
"txt": [
"1",
"1",
"1",
"1"
]
}, {
"id": 1,
"txt": [
"2",
"3",
"3",
"2"
]
}, {
"id": 1,
"txt": [
"3",
"4",
"5",
"3"
]
}, {
"id": 1,
"txt": [
"2",
"3",
"4",
"5"
]
}];
var arr = [];
_.map(res, function(d) {
_.map(d.txt, function(dd, i) {
arr[i] = (arr[i] != undefined && arr[i] != "" ? arr[i] : 0) + parseInt(dd);
});
});
console.log(arr);