How to pass an array to a function with parameter for each array value in JavaScript

1 Answer

0 votes
function sum(n1, n2, n3, n4, n5) {
    return n1 + n2 + n3 + n4 + n5;
}

const arr = [1, 2, 3, 4, 5];

console.log(sum(...arr)); 




/*
run:

15

*/

 



answered May 25, 2021 by avibootz
...