📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials jQuery in Practice Each Iterator

Each Iterator

4 min read
.each() iterates over a jQuery object calling a function for each element. $.each() iterates over plain arrays and objects. Return false inside the callback to break out of the loop early.

Iterating with .each()

// Iterate elements
$('li').each(function(index, element) {
  console.log(index, $(this).text());
});

// Iterate array
$.each([10, 20, 30], function(i, val) {
  console.log(i, val);
});

// Iterate object
$.each({ a: 1, b: 2 }, function(key, val) {
  console.log(key, val);
});