javascript create function with unknown number of parameters code example
Example 1: Pass unknown number of arguments into javascript function
var print_names = function(...names) {
for (let i=0; i<names.length; i++) console.log(names[i]);
}
Example 2: javascript unknown number of parameters
function add (...numbers) {
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i]
};
console.log(sum);
};
add(2, 3);
add(5, 3, 7, 2);