jQuery.makeArray()Method

jQuery 杂项方法jQuery Misc Methods

Examples

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(); //Apply an array method to the elements of the list $(arr).appendTo(document.body); })

Try it Yourself »

Definition and Usage

The $.makeArray() function is used to convert an array-like object into a real array object.

Note:Array-like objects have many properties of arrays (e.g., the length property, the [] array access operator, etc.), but they are not arrays after all, lacking the built-in methods inherited from the array's prototype object (e.g., pop(), reverse(), etc.).


Syntax

$.makeArray( object )

Parameter Description
object Object type The array-like object that needs to be converted into an array.


实例

More Examples

Convert to an array
Convert a jQuery object into an array.

jQuery 杂项方法jQuery Misc Methods

Other Extensions