[Solved] What is the reason for having array-like in JS [closed]


“Cannot loop over them”? The classic, traditional iteration over an array is:

for (var i = 0; i < arrayLike.length; i++) {
    doSomethingWith(arrayLike[i]);
}

This assumption is very deeply ingrained; in fact, arrays are mere plain objects in Javascript with the only addition of the .length property which has specific behaviour when numeric properties are set on the object and .push.

Everything else like .forEach, .map etc. are convenience additions which, yes, only exist on actual Array instances, not array-likes.

7

solved What is the reason for having array-like in JS [closed]