how can i pass another parameter instead of n1n2n3?

Just loop from array and get the output

function sumArray(arr){
  let total = 0;
  arr.forEach((i) => total+=i);
  return total;
}
console.log(sumArray([3,45,66]));

Or you can try with reduce as explained by Cristian

function sumArray(arr){
  const reducer = (previousValue, currentValue) => previousValue + currentValue;
  let total = arr.reduce(reducer)
  return total;
}
console.log(sumArray([3,45,66]));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top