Sunday, October 2, 2011

$.each(Object,Function)

$.each(Object obj, Function fn) returns Object
A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. This function is not the same as $().each() - which is used to iterate, exclusively, over a jQuery object. This function can be used to iterate over anything.

The callback has two arguments:the key (objects) or index (arrays) as first the first, and the value as the second.

Example:

This is an example of iterating over the items in an array, accessing both the current item and its
index.
$.each( [0,1,2], function(i, n){
alert( "Item #" + i + ": " + n );
});

No comments:

Post a Comment