jQuery.makeArray() method
Example
Convert a collection of HTML elements into a corresponding array
$
(
function
(
)
{
var
elems
=
document
.
getElementsByTagName
(
"
div
"
)
;
//
Return a node list
var
arr
=
jQuery
.
makeArray
(
elems
)
;
arr
.
reverse
(
)
;
//
Use an array method on the elements of the list
$
(
arr
)
.
appendTo
(
document
.
body
)
;
}
)
Try it »
Definition and Usage
The $.makeArray() function is used to convert an array-like object into a real array object.
**Note:** An array-like object has many properties of an array (such as the length property, the [] array access operator, etc.), but it is not an array after all, lacking the built-in methods inherited from the Array prototype (such as pop(), reverse(), etc.).
Syntax
$
.makeArray( object )
| Parameters | Description |
|---|---|
| object | Object type: The array-like object to be converted into an array. |
More examples
Convert to an array
Convert a jQuery object into an array.
jQuery Miscellaneous Methods