JavaScript quirk 8: array-like objects
[This post is part of a series on JavaScript quirks.] Some objects in JavaScript look like arrays, but aren’t. They are called array-like . This blog post looks at what exactly that means and how to best work with those objects. Array-like objects An array-like object has: indexed access to elements and the property length that tells us how many elements the object has. does not have: array methods such as push , forEach and indexOf . Two examples of array-like objects is the result of the DOM method document.getElementsByClassName() (many DOM methods return array-like objects) and the special variable arguments [1] . You can determine the number of arguments via arguments.length And you can access a single argument, e.g. read the first argument: arguments[0] Array methods, however, have to be borrowed. You can do that, because most of those methods are generic . Generic methods A generic method does not require this to be an array, it only requires this to have length an...