how loop through javascript array code example
Example 1: iterate array javascript
array = [ 1, 2, 3, 4, 5, 6 ];
for (index = 0; index < array.length; index++) {
console.log(array[index]);
}
Example 2: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
Example 3: loop through array javascript
const cities = ["Chicago", "New York", "Los Angeles"];
cities.map(city => {
console.log(city)
})
Example 4: javascript loop and array
var array = ["hello","world"];
array.forEach(item=>{
console.log(item);
});