1

Is there a way to get jQuery slice to return an array of elements instead of a jQuery object? Perhaps an alternative function from a jQuery compatible library?

Or do I have to covert into an array myself using makeArray (or doing it myself)?

(I ask because once I discovered each2, I am always imagining there is a slightly more optimized function out there for a given task).

1 Answer 1

5

Use .get() to return an "normal" array from a jQuery object.

Example:

var arr = $('div').slice(2, 4).get();
Sign up to request clarification or add additional context in comments.

1 Comment

.toArray() should actually be a little faster, since that's what .get() with no arguments calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.