For traversing an array-like object, is better use -- for performance -- Array.from( ).forEach()
or for
loop?
Example of an array-like object:
let childeNodes = document.querySelector('#someid').childNodes;
Iteration with Array.from().forEach()
:
Array.from(childNodes).forEach(node => {
// do something with node
})
Or iteration with for
:
for (let i = 0; i < childNodes.length; i++) {
// do something with childNodes[i]
}