What is the use of each function in jQuery?
Nitin Choudhary
In short way each is loop using we can travel selected container.$.each(selector, function( index, value ) {});
Each function is similar to foreach.if you get any array format value from resultset.we simply use each function in jquery. like jquery("#resultset").each(function(rs){ alert(rs[0].toString()); });
Each function is similar to loop in any language . It select all the element selected by selector and iterate one by one.
Each function is same as for loop in C#.so you can iterate through all the elements . Like if you have want to loop through all tables tr then you can do like$("table tr").each(function({// code here});
Description: 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.Note: The $.each() function internally retrieves and uses the length property of the passed collection. So, if the collection has a property called length — e.g. {bar: 'foo', length: 10} — the function might not work as expected.1 2 3 $.each([ 52, 97 ], function( index, value ) {alert( index + ": " + value ); }); This produces two messages:0: 52 1: 97
Each function is used to iterate each and every element of an object. It is used to loop DOM elements, arrays and the object properties.