I want to create a function with dynamic number of parameters. I have a string array like
['param1','param2','param3']
and i need to create a function with this array
function test(param1,param2,param3){
}
is there a way to do this?
I want to create a function with dynamic number of parameters. I have a string array like
['param1','param2','param3']
and i need to create a function with this array
function test(param1,param2,param3){
}
is there a way to do this?
You can use ...args
( rest parameter
) to collect dynamic number of parameters
function test(...args){
console.log(args)
}
test(1,2,3,4)
test(1,2,3)
Just pass the array as a parameter
var a=['param1','param2','param3']
function test(a){
console.log(a)
}
test(a)