javascript

Javascript Iterate Over All the Elements in an Array


In Javascript to Iterate Over All the Elements in an Array, we can use a functional approach.

const cars = ['bmw', 'tata', 'benz', 'kia', 'honda', 'suzuki', 'hyundai'];

for (const car of cars) {
    console.log(cars);
}

we can also use a for…of loop to Iterate Over All the Elements in an Array in the Javascript:

const cars = ['bmw', 'tata', 'benz', 'kia', 'honda', 'suzuki', 'hyundai'];

for (let i = 0; i < cars.length; ++i) {
    console.log(cars[i]);
}

we can also iterate over an array by passing a function to the Array.forEach() method.


Share on social media

//