Try something like this:
var arr = [[1,2,3], [4,5,6]];
var newArr = [];
arr.forEach(function(item) {
item = item.reduce(function(a, b) {
return a + b;
});
newArr.push([item]);
});
console.log(newArr);
To be a little more concise, you can use the values passed to the forEach callback: the element you are currently viewing, the index of that element, and the array itself:
arr.forEach(function(item, index, array) {
array[index] = [array[index].reduce(function (a, b) {
return a + b;
})];
});
source
share