Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Write a Loop with for...of1:28 with Guil Hernandez
for...of creates loop that repeats an action a given number of times.
Another way you might write a loop is with the for of loop, like for each,
for of creates a loop that repeats an action a given number of times.
You create a for of loop with the keyword, for
followed by a parentheses and curly braces.
Inside the parentheses, you provide for
of a variable that represents the current item being processed in the loop.
This is very similar to the movie parameter we just used inside for each.
So I'll again call the variable movie with var movie, and
you could also the let and const keywords I mentioned earlier here in place of var.
Now I'll follow the variable with the keyword of and
the name of the array we're looping over, in this case, movies.
Inside the curly braces you provide a statement or
action to be carried out for each element that gets passed into the loop.
I'll simply log each movie title to the console
with console.log and pass it in movie.
So as you can see, this loop statement is pretty simple to read.
It almost reads in plain English, for
every movie of the movies array, log it to the console.
I'll give this a save, refresh the browser, and
now over in the console we see a list of all the titles stored in the movies array.
You need to sign up for Treehouse in order to download course files.Sign up