There's a few other ways to iterate in JavaScript:
for-of
const array = [1,2,3]; for (const num of array) { console.log(num); }
forEach
const array = [1,2,3]; array.forEach(num => { console.log(num); }; // or array.forEach(console.log);
Functional programming - map
const array = [1,2,3]; array.map(console.log);
Note: forEach(console.log) will print the item, index and the array - developer.mozilla.org/en-US/docs/W...
forEach(console.log)
Array#forEach((item, index, array) => { /*...*/ })
There is no need to use breckets in lambda:
const array = [1,2,3]; array.forEach(num => console.log(num));
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There's a few other ways to iterate in JavaScript:
for-of
forEach
Functional programming - map
Note:
forEach(console.log)
will print the item, index and the array - developer.mozilla.org/en-US/docs/W...There is no need to use breckets in lambda: