Unlimited arguments in a JavaScript function

前端 未结 9 1872

Can a JavaScript function take unlimited arguments? Something like this:

testArray(1, 2, 3, 4, 5...);

I am trying:

var arr          


        
9条回答
  •  不知归路
    2020-12-07 18:22

    There are some legacy methods but I prefer the ES6 and newer versions, So if I wanna implement this, I wrote it like below:

    const func = ...arg => console.log(arg);
    

    Simple and cutting edge of tech.

提交回复
热议问题