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

1 Answer

0 votes
function sum(n1: number, n2: number, n3: number, n4: number, n5: number, n6: number) {
    return n1 + n2 + n3 + n4 + n5 + n6;
}
 
const arr = [34, 2, 9, 1, 8, 60];
 
console.log(sum(...arr)); 
 
 
 
 
/*
run:
 
114 
 
*/

 



answered Dec 18, 2021 by avibootz
...