This content originally appeared on CodeSource.io and was authored by Deven
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.
The post Javascript Iterate Over All the Elements in an Array appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-02-07T13:41:07+00:00) Javascript Iterate Over All the Elements in an Array. Retrieved from https://www.scien.cx/2021/02/07/javascript-iterate-over-all-the-elements-in-an-array/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.