jedierikb
jedierikb

Reputation: 13099

jQuery slice to return an array?

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).

Upvotes: 1

Views: 202

Answers (1)

gen_Eric
gen_Eric

Reputation: 227290

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

Example:

var arr = $('div').slice(2, 4).get();

Upvotes: 5

Related Questions