On top of this, I found that jQuery is using the following method to check for Array-like objects:
isArray = elems instanceof jQuery || length !== undefined && typeof length === “number” && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
The first and last conditions are checking for a jQuery collection and a real Array respectively, and the things in between are essentially checking to see if the object has a length property which is a number, and that it actually contains a first element (at ) and a last element (at [length-1]). (or simply is empty with a length of 0). This is what I came up with after the interview (I settled for a real Array checking just to get by). I originally thought it was pretty crude, as the object can be really sparse and still pass this check. But after some thought, it seems to be ok, because being sparse doesn’t interfere with the ability to use Array prototype methods on the Array-like object, as long as the length property matches the largest index.