<pclass="desc"><strong>Description: </strong>A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. Arrays and array-like objects with a length property (such as a function's arguments object) are iterated by numeric index, from 0 to length-1. Other objects are iterated via their named properties.
<pclass="arguement"><strong>collection</strong>The object or array to iterate over.</p>
<pclass="arguement"><strong>callback(indexInArray, valueOfElement)</strong>The function that will be executed on every object.</p>
</li></ul>
<divclass="longdesc">
<p>The <code>$.each()</code> function is not the same as <ahref="/each/">.each()</a>, which is used to iterate, exclusively, over a jQuery object. The <code>$.each()</code> function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time. (The value can also be accessed through the <code>this</code> keyword.)</p>
<p>If a map is used as the collection, the callback is passed a key-value pair each time:</p>
<pre>var map = {
'flammable': 'inflammable',
'duh': 'no duh'
};
$.each(map, function(key, value) {
alert(key + ': ' + value);
});</pre>
<p>Once again, this produces two messages:</p>
<p>
<spanclass="output">flammable: inflammable</span><br><spanclass="output">duh: no duh</span>
</p>
<p>We can break the <code>$.each()</code> loop at a particular iteration by making the callback function return <code>false</code>. Returning <em>non-false</em> is the same as a <code>continue</code> statement in a for loop; it will skip immediately to the next iteration.</p>
</div>
<h3>Examples:</h3>
<divid="entry-examples"class="entry-examples">
<divid="example-0">
<h4>Example: <spanclass="desc">Iterates through the array displaying each number as both a word and numeral</span>