Sum array in javascript

hi I want to sum 2 arrays using javascript, how can i do?
Deepak Sharma
Asked 25-12-2020
16

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.
Ankur Rajput
Asked 28-01-2020
45 Likes
Comments
Write comment

Submit your answer