|
3 | 3 | <title>jQuery.map()</title>
|
4 | 4 | <signature>
|
5 | 5 | <added>1.0</added>
|
6 |
| - <argument name="array" type="Array"> |
7 |
| - <desc>The Array to translate.</desc> |
| 6 | + <argument name="array" type="ArrayLikeObject"> |
| 7 | + <desc>The Array or an Array-like object to translate.</desc> |
8 | 8 | </argument>
|
9 | 9 | <argument name="callback" type="Function">
|
10 | 10 | <argument name="elementOfArray" type="Object" />
|
|
16 | 16 | <signature>
|
17 | 17 | <added>1.6</added>
|
18 | 18 | <argument name="object" type="Object">
|
19 |
| - <desc>The Object to translate.</desc> |
| 19 | + <desc>The non-Array-like Object to translate.</desc> |
20 | 20 | </argument>
|
21 | 21 | <argument name="callback" type="Function">
|
22 | 22 | <argument name="propertyOfObject" type="Object" />
|
|
28 | 28 | <desc>Translate all items in an array or object to new array of items.</desc>
|
29 | 29 | <longdesc>
|
30 | 30 | <p>If you wish to process a jQuery object — for example, <code>$('div').map( callback );</code> — use <a href="/map/">.map()</a> instead. </p>
|
31 |
| - <p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p> |
32 |
| - <p>Array-like objects — those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index — must be converted to actual arrays before being passed to <code>$.map()</code>. The jQuery library provides <a href="/jQuery.makeArray/">$.makeArray()</a> for such conversions.</p> |
| 31 | + <p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays and array-like objects only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p> |
| 32 | + <p>Array-like objects — those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index — may be passed to <code>$.map()</code>.</p> |
33 | 33 | <pre><code>
|
34 |
| -// The following object masquerades as an array. |
| 34 | +// The following object is array-like. |
35 | 35 | var fakeArray = { "length": 2, 0: "Addy", 1: "Subtracty" };
|
36 | 36 |
|
37 |
| -// Therefore, convert it to a real array |
38 |
| -var realArray = $.makeArray( fakeArray ) |
39 |
| - |
40 |
| -// Now it can be used reliably with $.map() |
| 37 | +// It can be used reliably with $.map() |
41 | 38 | $.map( realArray, function( val, i ) {
|
42 | 39 | // Do something
|
43 | 40 | });
|
|
0 commit comments