From the course: Computer Science Principles Lab: JavaScript
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use loops with arrays - JavaScript Tutorial
From the course: Computer Science Principles Lab: JavaScript
Use loops with arrays
- [Instructor] When you have values in an array, it is common to want to perform actions on each one of the items. You can use a for loop to iterate through all the items in the array and access each element individually. There are two ways to do this. The first is with a standard for loop. When you create a for loop, you need to define the iterator variable, and then use that value to test if the loop should continue or not. Each array has a property called length that you can use in your for loop conditional test to see if the iterator variable exceeds the length of the array. If I have an array like this one, there are four elements, but remember, the last element has an index number of three, so it is one less than the length of the array. We can use this to build our for loop. We start the for loop like any other, for. We create the iterator variable. for var i equals zero. But in our test, we want to verify that the iterator is less than the value of the array length property…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Capture input from the user9m 17s
-
(Locked)
Manage different variable types6m 43s
-
(Locked)
Create conditional tests12m 16s
-
(Locked)
Build compound conditional tests8m 42s
-
(Locked)
Use while loops4m 13s
-
(Locked)
Use for loops7m 35s
-
Create arrays to store groups of values3m 36s
-
(Locked)
Use loops with arrays3m 26s
-
(Locked)
Changing arrays3m
-
(Locked)
-