Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
we are comparing here forEach & for of construct
const fruits = ['apple', , 'orange', 'kiwi', 'grapes', 'pineapple'];
for (fruit of fruits) {
console.log(fruit);
}
// Output
// apple
// undefine
// orange
// kiwi
// grapes
// pineapple
fruits.forEach(f => console.log(f));
// Output
// apple
// orange
// kiwi
// grapes
// pineapple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment