how would you iterate all the elements of an array? code example
Example 1: iterate through list javascript
const array = ["hello", "world"];
for (item of array) {
}
Example 2: js loop through array
for (const color of colors){
console.log(color);
}
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
}
Example 3: loop through array javascript
const cities = ["Chicago", "New York", "Los Angeles"];
cities.map(city => {
console.log(city)
})