Check out a free preview of the full Advanced JS Fundamentals to jQuery & Pure DOM Scripting course:
The "Exercise 9: $.each()" Lesson is part of the full, Advanced JS Fundamentals to jQuery & Pure DOM Scripting course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will implement the $.each() method which will iterate over arrays or other objects.

Get Unlimited Access Now

Transcript from the "Exercise 9: $.each()" Lesson

>> [MUSIC]

>> Justin Meyer: So $.each, this just iterates over something. It iterates either over on an array-like thing or an object. So it's gonna go through, here it's gonna go through an array and for every item in the array callback with the index of the array so 0, 1, 2. It's gonna callback this function and then also with the value at that index so a, b, c.

[00:00:37] And then if you pass $.each a object, it's going to call back with the property so foo, zed and then the value bar, ted.
>> Justin Meyer: So we're gonna implement $.each. So another ten minutes on the board unless there are any other questions how to do this. So this is we're going to be being passed a function and you have to call that function.

[00:01:07] You're going to set up a loop a for loop or for in loop depending on if this is array-like or not. Depending on if this is array-like or not, you're not going to do either type of loop. You're gonna do a for in loop if it's not array-like and a for, a normal for loop if it is array-like.

[00:01:27] And then you're gonna call this function back for each iteration of that loop with the index in value.