1var colors = ["red","blue","green"];
2for (var i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1const array = ["one", "two", "three"]
2array.forEach(function (item, index) {
3 console.log(item, index);
4});
1var myStringArray = ["hey","World"];
2var arrayLength = myStringArray.length;
3for (var i = 0; i < arrayLength; i++) {
4 console.log(myStringArray[i]);
5 //Do something
6}
1/* ES6 */
2const cities = ["Chicago", "New York", "Los Angeles"];
3cities.map(city => {
4 console.log(city)
5})
6
1let numbers = [1,2,3,4,5];
2let numbersLength = numbers.length;
3for ( let i = 0; i < numbersLength; i++) {
4 console.log (numbers[i]);
5}