.toArray() returns a native JavaScript Array of every DOM element in the jQuery set (since jQuery 1.4). It takes no arguments. The array holds the same live nodes — not jQuery wrappers and not clones.
Remember
$(selector).toArray() → Array of DOM elements
jQuery set → [el0, el1, el2, …]
native Array (document order)
then use: reverse(), map(), filter(), for…of
.get() with no args ≈ same idea
.empty selection → []
Use Array methods on the result (reverse, map, …).
Wrap a node again with $(node) if you need jQuery methods.
Piece
Required?
Role
jQuery set
Yes
Source collection of matched elements
Arguments
None
Method takes no parameters
Return
—
New Array of DOM elements
Since
—
jQuery 1.4
Pseudocode
Pseudocode
toArray():
result = new Array
for each element in this jQuery set (document order):
result.push(element) // same node reference
return result
// empty set → []
Reference
Cheat Sheet
Keep these facts handy when bridging jQuery and Array APIs.
Topic
Detail
Syntax
.toArray()
Returns
Native Array of DOM nodes
Order
Document order (same as the set)
Empty set
[]
vs .get()
.get() ≈ all; .get(i) = one
Clones?
No — references to live nodes
Since
jQuery 1.4
Try it
Live Preview
Convert a small jQuery set of list items and try Array methods on the result.
Browser demo of .toArray() — same idea as the examples below.
Result
length → 3
tags → LI, LI, LI
Array.isArray → true
/* native Array of DOM elements */
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Convert a Selection to an Array
Get a native Array of matched elements and inspect length / tags.
jQuery
var items = $("li").toArray();
console.log(items.length); // 3
console.log(Array.isArray(items)); // true
console.log(items[0].tagName); // LI
Not a jQuery object.items has Array methods, not .css().
Example 2 — Reverse with Array Methods
Official pattern: convert, reverse, then read text from each node.
jQuery
var divs = $("div.demo").toArray().reverse();
var texts = [];
for (var i = 0; i < divs.length; i++) {
texts.push(divs[i].textContent);
}
console.log(texts.join(" ")); // Three Two One
Safe. You can call Array methods without a null check.
Rule. Empty jQuery set → empty native array.
Edge Cases & Pitfalls
Check these before mixing jQuery sets and Arrays.
type
Nodes, not jQuery objects
arr[0].text() fails — use arr[0].textContent or $(arr[0]).text().
live
References, not clones
Changing a node in the array updates the live DOM. Use .clone() if you need copies.
mutate
reverse() mutates the array
Array reverse changes that array in place. It does not reorder the original jQuery set.
get
Do not confuse .get(i) with an array
.get(0) is one element. .toArray() / .get() is the full list.
Compatibility
Browser Support
.toArray() needs jQuery 1.4+ loaded. It works in every modern browser that can run jQuery.
✓ jQuery 1.4+
.toArray()
Works in Chrome, Firefox, Safari, and Edge when jQuery 1.4+ is loaded. Returns a standard Array of matched DOM elements.
100%With jQuery 1.4+
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.toArray()Universal
Bottom line: Safe for all supported jQuery versions. Prefer it when you need native Array methods on a selection.
Analysis
Performance Notes
Approach
Cost
Best for
.toArray()
O(n) copy of references
Need a real Array once
Stay on jQuery set
No extra array
jQuery-only chaining
.get(i)
O(1)
Single element by index
Cost is proportional to the number of matched elements. For huge sets, convert only when you need Array APIs — otherwise keep chaining on the jQuery object.
Remember
Key Takeaways
Role: jQuery set → native Array of DOM elements.
Why: unlock reverse, map, filter, and friends.
vs get: whole array vs one element by index.
Empty: no matches → [].
One line:.toArray() hands you a real Array of the matched DOM nodes.
Frequently Asked Questions
.toArray() returns a standard JavaScript Array of all DOM elements in the jQuery set, in document order. It takes no arguments. Available since jQuery 1.4.
.get() with no arguments also returns an array of matched elements — same idea as .toArray(). .get(index) returns one DOM element. Prefer .toArray() when you clearly want a native array; use .get(n) for a single element.
Plain DOM Element nodes, not jQuery wrappers. Wrap again with $(node) if you need jQuery methods.
To use Array methods such as reverse(), map(), filter(), or for…of, or to pass the list to APIs that expect a real Array.
An empty array: []. For example $("#missing").toArray() is [].
No. The new Array holds references to the same live DOM nodes. Changing a node in the array changes the element in the page.