Skip to main content

Explain .each() and iteration over elements.

Mid JQuery
Quick Answer $.each(collection, function(index, value) {}) iterates arrays and objects. $("li").each(function(i, el) { $(el).addClass("item-" + i) }) iterates matched jQuery elements. Unlike native .forEach(), jQuery .each() has different argument order (index first, element second). Inside the callback, this refers to the current element (as a DOM node).

Answer

.each() iterates matched elements.
Provides index + element.
Used for styling, updates, or bulk DOM work.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice