1

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?

konuralpt
  • 263
  • 2
  • 11

2 Answers2

3

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)
Code Maniac
  • 37,143
  • 5
  • 39
  • 60
0

Just pass the array as a parameter

var a=['param1','param2','param3']
function test(a){
console.log(a)
}
test(a)
ellipsis
  • 12,049
  • 2
  • 17
  • 33