-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathjQuery.makeArray.xml
51 lines (51 loc) · 1.85 KB
/
jQuery.makeArray.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0"?>
<entry type="method" name="jQuery.makeArray" return="Array">
<title>jQuery.makeArray()</title>
<signature>
<added>1.2</added>
<argument name="obj" type="PlainObject">
<desc>Any object to turn into a native Array.</desc>
</argument>
</signature>
<desc>Convert an array-like object into a true JavaScript array.</desc>
<longdesc>
<p>Many methods, both in jQuery and in JavaScript in general, return objects that are array-like. For example, the jQuery factory function <code>$()</code> returns a jQuery object that has many of the properties of an array (a length, the <code>[]</code> 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 <code>.pop()</code> and <code>.reverse()</code>).</p>
<p>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.</p>
</longdesc>
<example>
<desc>Turn a collection of HTMLElements into an Array of them.</desc>
<code><![CDATA[
// 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 );
]]></code>
<css><![CDATA[
div {
color: red;
}
]]></css>
<html><![CDATA[
<div>First</div>
<div>Second</div>
<div>Third</div>
<div>Fourth</div>
]]></html>
</example>
<example>
<desc>Turn a jQuery object into an array</desc>
<code><![CDATA[
var obj = $( "li" );
var arr = $.makeArray( obj );
]]></code>
<results><![CDATA[
( typeof obj === "object" && obj.jquery ) === true;
jQuery.isArray( arr ) === true;
]]></results>
</example>
<category slug="utilities"/>
<category slug="version/1.2"/>
</entry>