hi I want to sum 2 arrays using javascript, how can i do?
Answer (1)
You can solve your query using reduce() method in javascript
Use the JavaScript reduce() Method
var array1 = [95, 782, 523, 474];
var array2 = [55, 12, 50];
// Getting sum of numbers of aray1.
var sum1 = array. reduce(function(a, b){
return a + b;
}, 0);
// Getting sum of numbers of aray2.
var sum2 = array2. reduce(function(a, b){
return a + b;
}, 0);
console. log(sum1 + sum2); // Prints: 1991.