Iterables in JavaScript

Any object that can be iterated through the for of loop is called iterable.

Arrays are one of the special cases of iterable objects:

javascriptlet arr = [1, 2, 3];

for (let elem of arr) {
  console.log(elem);
}

Map collections are also iterable objects:

javascriptlet map = new Map();
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);

for (let elem of map) {
  console.log(elem);
}

NodeList collections are also iterable objects:

javascriptlet elems = document.querySelectorAll('p');

for (let elem of elems) {
  console.log(elem);
}

In addition, JavaScript allows you to make anything iterable. There are special tricks for this that we will study in the following lessons:

javascriptlet obj = {a: 1, b: 2, c: 3};

// here are some tricky tricks

for (let elem of obj) { // can be iterated
  console.log(elem);
}
Задание 1

Give more examples of entities you know that are iterable objects.