Wednesday, 20 July 2011

Iterating an Array using jQuery each() method

Try the below JavaScript code.



var arr = ['a','b','c'];

$.each(arr, function(index, obj) {
// 'this' is the object of the current iteration
alert(this);
//This will alert a or b or c in each iteration
});

$(arr).each(function(index, obj) {
// 'obj' is the object of the current iteration
alert(obj);
//This will alert a or b or c in each iteration
});

No comments:

Post a Comment