Skip to content

Instantly share code, notes, and snippets.

@mohanramphp
Created February 28, 2021 13:46
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 mohanramphp/0767c405d61f4b23c9a7a3a2c716bca8 to your computer and use it in GitHub Desktop.
Save mohanramphp/0767c405d61f4b23c9a7a3a2c716bca8 to your computer and use it in GitHub Desktop.
const students = ["Mohan", "Ram", "Jeeva", "Priya"];
//since students object is an iterable, we can use with iteration mechanism such as for, spread operators etc.
for (let student of students) {
console.log(student);
}
// prints
// "Mohan"
// "Ram"
// "Jeeva"
// "Priya"
console.log(...students); // Mohan Ram Jeeva Priya
const employees = {};
for (let employee of employees) {
console.log(employee);
}
// Uncaught TypeError: employees is not iterable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment