react function unknown args code example
Example 1: javascript x number of parameters
function display_numbers(...numbers) {
colors.forEach(function(x) {
console.log(x);
});
}
// call it like:
display_numbers(1)
display_numbers(1, 2, 3, 4)
display_numbers(1, -1, 9, 0, 2)
Example 2: 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]);
}