How to get a slice from “arguments”

后端 未结 7 1959
天命终不由人
天命终不由人 2020-12-01 09:10

All you know that arguments is a special object that holds all the arguments passed to the function.

And as long as it is not an array - you cannot use

7条回答
  •  时光说笑
    2020-12-01 09:17

    Q. How to slice everything but first element from arguments?

    The following will return an array containing all arguments except the first:

    var slicedArgs = Array.prototype.slice.call(arguments, 1);
    

    You don't have to convert arguments to an array first, do it all in one step.

提交回复
热议问题