let elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el.name); };
// Spread operator
[...elements].forEach(callback);
// Array.from()
Array.from(elements).forEach(callback);
// for...of statement
for (let div of elements) callback(div);
fichier code
JS Bin on jsbin.com
//itérator
elements[Symbol.iterator]();
elements.forEach(callback)
console.log("-----");
elements[Symbol.iterator] = function* () {
yield "un nd";
yield 2;
yield "fin";
};
console.log([...elements]);