1 line
1.7 KiB
JSON
1 line
1.7 KiB
JSON
{"name":"jQuery.makeArray","type":"method","title":"jQuery.makeArray()","deprecated":null,"removed":null,"desc":"Convert an array-like object into a true JavaScript array.","categories":["utilities","version/1.2"],"entries":[{"return":"Array","signatures":{"added":"1.2","argument":{"desc":"Any object to turn into a native Array.","name":"obj","type":"PlainObject"}},"examples":[{"desc":"Turn a collection of HTMLElements into an Array of them.","code":"\n// Returns a NodeList\nvar elems = document.getElementsByTagName( \"div\" );\n// Convert the NodeList to an Array\nvar arr = jQuery.makeArray( elems );\n// Use an Array method on list of dom elements\narr.reverse();\n$( arr ).appendTo( document.body );\n","css":"\n div {\n color: red;\n }\n","html":"\n<div>First</div>\n<div>Second</div>\n<div>Third</div>\n<div>Fourth</div>\n"},{"desc":"Turn a jQuery object into an array","code":"\nvar obj = $( \"li\" );\nvar arr = $.makeArray( obj );\n","results":"\n( typeof obj === \"object\" && obj.jquery ) === true;\njQuery.isArray( arr ) === true;\n"}],"longdesc":"\n <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>\n <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>\n "}]} |