From the course: Learning the JavaScript Language

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

For loops: Enumerative

For loops: Enumerative

- [Instructor] In this video, we're going to look at another type of for loop, the Enumerative for loop. This one is used on arrays or objects. It can take various forms and while useful, you do need to pay attention when using this tool. We'll look first at iterating over the items in an array. I have this variable called "pageNames". It's an array of six items. We've seen how to iterate over this array using Sequential for loops, where you would set a variable to zero, give it a stopping condition and increment every time through. A less verbose way to do this is with the for in loop. This is what it looks like. I have the word "for" followed by parenthesis and then the expression inside is "var", in this case, you could also use "let" and then I choose whatever variable name I want. I'm using "p" in this case, which is short for pageName, from "pageNames". You might often see counter variables in loops abbreviated…

Contents