The .toArray() method turns a jQuery collection into a plain JavaScript Array of DOM elements. This tutorial covers the official demos, using native Array methods like .reverse() and .map(), comparisons with .get(), empty selections, five examples, and try-it labs.
01
.toArray()
Native Array
02
DOM nodes
Not jQuery
03
.reverse()
Array methods
04
vs .get()
Similar API
05
Empty
Returns []
06
Since 1.4
Stable API
Fundamentals
Introduction
A jQuery object is array-like — it has a .length and numeric indexes — but it is not a real JavaScript Array. That means some Array methods are missing or behave differently.
Since jQuery 1.4, .toArray() bridges that gap: it returns every matched DOM element in a standard array so you can call .reverse(), .map(), .filter(), for…of, or hand the list to another library.
The nodes are the same live elements in the document (not clones). Pair this topic with collection helpers like .size() / .length, and browse the jQuery DOM hub for related methods.
Concept
Understanding the .toArray() Method
.toArray() copies the matched set into a new Array instance. Each entry is a raw DOM element. Order matches the jQuery collection (typically document order).
After conversion you leave the jQuery chaining world. To call jQuery methods again on one item, wrap it: $(nodes[0]).addClass("x"). Or wrap the whole array: $(nodes).
💡
Beginner Tip
Think: $("li") = jQuery toolbox. $("li").toArray() = plain box of DOM elements you can sort, reverse, or map with normal JavaScript.
Foundation
📝 Syntax
Signature (jQuery 1.4+):
jQuery
.toArray()
Parameters
None — this method does not accept any arguments.
Return value
Array — all elements in the jQuery set as native DOM nodes.
[object HTMLLIElement],[object HTMLLIElement],…
A native Array of the matched <li> DOM nodes
How It Works
$("li") builds the jQuery set. .toArray() returns those same elements as a standard array. Alerting an array of elements shows the browser’s default object string for each node.
Example 2 — Official Pattern: Reverse Div Contents
Convert all <div> elements to an array, reverse it, then join their innerHTML for display.
jQuery
function disp( divs ) {
var a = [];
for ( var i = 0; i < divs.length; i++ ) {
a.push( divs[ i ].innerHTML );
}
$( "span" ).text( a.join( " " ) );
}
disp( $( "div" ).toArray().reverse() );
Reversed - Three Two One
Native .reverse() works because toArray() returned a real Array
How It Works
jQuery collections are not full Arrays, so chaining .reverse() on $("div") is not the right tool. After .toArray(), Array.prototype methods apply. The demo only reverses the array order used for reading text — it does not reorder the DOM.
📈 Practical Patterns
Mapping, empty sets, and how .get() compares.
Example 3 — Map Elements to Text With .map()
Once you have a native array, use Array.prototype.map to collect strings.
Alpha | Beta | Gamma
Native map runs on DOM elements from toArray()
How It Works
.toArray() unlocks the standard Array toolkit. You could also use jQuery’s .map() and .get(), but converting first is often clearer when the rest of the pipeline is plain JavaScript.
Example 4 — Empty Selection Returns []
Missing matches still return a real (empty) array — safe for .length checks and spreads.
toArray length === get() length: true
.first tagName: LI
Use .toArray() for clarity; .get(i) for one node
How It Works
Both dump the collection to an array when called without an index. Choose .toArray() when readability matters; use .get(i) (or $("li")[i]) when you only need one element.
Applications
🚀 Common Use Cases
Array pipelines — reverse, sort, map, or filter matched elements with native methods.
Interop — pass DOM nodes to libraries that expect a real Array.
Debugging — inspect the matched set as a plain list in the console.
Custom loops — for…of or indexed for over DOM elements.
Partial extraction — convert, then take a slice of nodes for a batch update.
Readable intent — prefer .toArray() over .get() when the goal is clearly “become an Array.”
🧠 How .toArray() Converts the Set
1
Match with jQuery
Select elements into a jQuery collection.
Select
2
Call .toArray()
Build a new Array holding references to those DOM nodes.
Convert
3
Use Array APIs
Reverse, map, filter, or iterate with plain JavaScript.
Array
4
📋
Optional: wrap again
$(nodes) or $(nodes[i]) to return to jQuery.
Important
📝 Notes
Available since jQuery 1.4; still present in modern jQuery 3.x / 4.x.
Returns an Array of DOM elements — not jQuery objects.
Does not clone nodes; array entries are live element references.
Empty selections return [].
.get() with no arguments is effectively the same dump to an array.
Reversing the array does not reorder the DOM unless you move nodes yourself.
Modern alternative: Array.from($("li")) or [...$("li")] in environments that support them — .toArray() remains the clearest jQuery API.
Compatibility
Browser Support
.toArray() has been part of jQuery since 1.4+. It works in every browser supported by your jQuery build — including modern evergreen browsers with jQuery 3.x and 4.x.
✓ jQuery 1.4+
jQuery .toArray()
Stable collection-to-Array bridge across jQuery 1.4–4.x. No browser polyfills required — jQuery normalizes the conversion.
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()1.4+
Bottom line: Use it whenever you need native Array methods on matched DOM elements.
Wrap Up
Conclusion
.toArray() is the straightforward way to leave jQuery’s collection type and work with a real JavaScript array of DOM elements. Reach for it when Array methods, loops, or third-party APIs expect a native list.
Use .toArray() before native .map / .filter / .reverse
Prefer it over .get() when intent is “give me an Array”
Re-wrap with $() if you need jQuery methods again
Remember empty selections return [], not null
Keep DOM mutations explicit — reversing an array alone does not move nodes
❌ Don’t
Expect array entries to be jQuery objects
Assume .toArray() clones elements
Call jQuery chain methods on the returned array without wrapping
Confuse array order changes with visual DOM order changes
Convert to an array when a simple jQuery .each() would suffice
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .toArray()
The bridge from jQuery collections to native Arrays.
5
Core concepts
[]01
Returns
Array
Native
DOM02
Holds
Elements
Live refs
⇄03
Like
.get()
No index
∅04
Empty
[]
Safe
1.405
Since
jQuery 1.4
API
❓ Frequently Asked Questions
.toArray() returns a standard JavaScript Array containing all DOM elements in the current jQuery set, in document order. It takes no arguments. Available since jQuery 1.4.
Calling .get() with no arguments also returns an array of all matched elements — the same idea as .toArray(). .get(index) returns a single DOM element (or undefined). Prefer .toArray() when you want a clear “give me a native array” intent; use .get(n) for one element by index.
Plain DOM Element nodes (HTMLElement, etc.), not jQuery wrappers. To use jQuery methods on one of them again, wrap it: $(array[0]).
So you can use Array methods that jQuery collections do not expose the same way — for example .reverse(), .map(), .filter(), .find(), for…of, or pass the list into APIs that expect a real Array.
An empty array: []. For example $("#missing").toArray() is [].
It builds a new Array that holds references to the same DOM nodes already in the page (or in memory). It does not clone elements. Mutating a node in the array mutates the live DOM element.
Did you know?
.toArray() arrived in jQuery 1.4 alongside other collection refinements. Before that, developers often relied on .get() with no arguments or manual loops pushing this into an array inside .each(). The dedicated method made the “I need a real Array” intent obvious in reading and reviewing code.