Unlimited arguments in a JavaScript function

前端 未结 9 1871

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:18

    With ECMAScript 6, you can use rest of arguments syntax:

    const testArray = (...args) => {
        console.log(args);
    };
    
    testArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    

提交回复
热议问题