jQuery.makeArray()

Convert an array-like object into a true JavaScript array.

jQuery.makeArray(obj)🡢 Array

obj PlainObjectAny object to turn into a native Array.

Many methods, both in jQuery and in JavaScript in general, return objects that are array-like. For example, the jQuery factory function $() returns a jQuery object that has many of the properties of an array (a length, the [] array access operator, etc.), but is not exactly the same as an array and lacks some of an array's built-in methods (such as .pop() and .reverse()).

Note that after the conversion, any special features the object had (such as the jQuery methods in our example) will no longer be present. The object is now a plain array.

Turn a collection of HTMLElements into an Array of them.

JS
<div>First</div>
<div>Second</div>
<div>Third</div>
<div>Fourth</div>
CSS
div {
  color: red;
}
HTML
// Returns a NodeList
var elems = document.getElementsByTagName("div");
// Convert the NodeList to an Array
var arr = jQuery.makeArray(elems);
// Use an Array method on list of dom elements
arr.reverse();
$(arr).appendTo(document.body);
DEMO

Turn a jQuery object into an array

HTML
var obj = $("li");
var arr = $.makeArray(obj);
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)