When, for example:
var obj = { 0: 'first', length: '1' }; alert(obj.length === +obj.length);
Underscore each is common, so it can work with objects other than array . Same as ECMA5 forEach
The forEach function is intentionally shared; it does not require this value to be an Array object. Therefore, it can be passed to other types of objects for use as a method. Whether the forEach function can be successfully applied to the host object is implementation dependent.
So, underlining checks the correctness of the property of the length object. And they consider the arrayLike object for this iteration method only if the length object returns number , which is not NaN , and, of course, is not string . Thus, in my example above, obj will fall into its keys iteration if there is no native / polylized forEach .
source share