Traversing an Array

Run Settings
LanguageJavaScript
Language Version
Run Command
// print all names in an array function printNames(console) { var names = ["Ben", "Jafar", "Matt", "Priya", "Brian"], counter; for (counter = 0; counter < names.length; counter++) { console.log(names[counter]); } } // Did we need to specify the order in which the names were printed? // Why or why not?
// use forEach to print all the names in an array function(console) { var names = ["Ben", "Jafar", "Matt", "Priya", "Brian"]; names.forEach(function(name) { console.log(name); }); } // forEach allows us to specify what we want to happen to each item // in the array, but HIDES how the array is traversed.
Editor Settings
Theme
Key bindings
Full width
Lines