jQuery.each(collection, callback) (alias $.each) is a generic iterator for arrays, array-like objects, and plain objects (since jQuery 1.0). It returns the collection you passed in.
Syntax
Start with these common calls. Keep them short and readable.
Break. When letter === "c", return false ends the loop.
Skipped."d" is never visited.
Frequently Asked Questions
jQuery.each(collection, callback) walks every item in an array, array-like object, or plain object and runs your callback once per entry. It is a generic iterator — not limited to DOM selections.
jQuery.each() is a static utility that accepts any collection. $(selector).each() only iterates elements in a jQuery DOM wrapper. Prefer $.each for arrays/objects and .each() for selected elements.
Return false from the callback to break immediately (like break in a for loop). Any other return value continues to the next item.
It returns its first argument — the same collection you passed in — so you can reuse the array or object after iterating.
Yes. this is the current value. For primitives, JavaScript boxes them as objects when accessed via this.
Use $.each when you need plain objects, array-like collections, or early exit with return false. Array.forEach only works on arrays and cannot break cleanly.