Post On : January 20, 2020

Hello all, We dont have any pre default function to do sum of an array. But fortunetly we can use array_reduce function for us.

Please have a look on below function for it.

const data = [1,2,9,5];
const sum = data.reduce((a,b)=> a+b);
console.log(sum);

Output is shown in below screenshot.

Thank you.

Catagory :Javascript