Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

javascript - How to get a slice from "arguments"

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 something like arguments.slice(1).

So the question - how to slice everything but first element from arguments?

UPD:

seems like there is no way without converting it to an array with

var args = Array.prototype.slice.call(arguments);

If someone posts another solution it would be great, if not - I'll check the first one with the line above as an answer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...