Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 22, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptschat/e12e8cf3eaa357bcd7160ac3238da47d to your computer and use it in GitHub Desktop.
Save scriptschat/e12e8cf3eaa357bcd7160ac3238da47d to your computer and use it in GitHub Desktop.
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