Unlimited arguments in a JavaScript function

前端 未结 9 1832

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

    function toArray() {
       return arguments;
    }
    
    var myargs = toArray(1, 2, 3, 4, 5, 6);
    

    The arguments keyword is available in every js function

提交回复
热议问题