Explore variations on the for loop that execute once per item in a collection: for in, for of.
- [Instructor] In this video, we're going to look at…another type of for loop, the enumerative for loop.…This is one that you can use on arrays or objects,…and it's very useful,…but you may need to be a little careful with it.…So here I have a couple of code samples.…First we'll look at iterating over an array with this thing.…I have a variable called pageNames.…It's an array with six items.…Now to iterate over this using the techniques…we already know, I could use a for loop…where I'm sending I to zero, going up to the length…of the pageNames array and incrementing every time I go.…There's another way to do this,…that uses the enumerative for loop.…
This is what it looks like.…We start out with for followed by parentheses again,…and I'm initializing a variable,…but instead of doing all the other stuff…where I'm setting an upper bound…and increment and decrement or however it is…that I need to traverse that item.…I'm just using the key word in,…and then the name of the array.…Each time through this loop,…the variable p gets set to a different key from this array.…
- Using a text editor
- Declaring and assigning variables
- Booleans and the quest for truth
- Working with objects and arrays
- Using operators and control structures
- Iterating with loops
- Objects, references, and functions
- Promises, async, and await
Skill Level Beginner
1. Getting Started
2. Variables and Types
3. Objects, Arrays, and More
4. Operators and Control Structures
5. Iterating with Loops
7. More Advanced Pieces
Next steps3m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.