3 ms·
Array.isArray() would be more reliable than testing if it has a property "length" :/ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_O
by wildpeaks 12y ago
Array.isArray() would be more reliable than testing if it has a property "length" :/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- mkozlows 12y agoExcept as MDN says, that works in IE9+, and jQuery 1.x works in IE6+.
- wildpeaks 12y agoMDN has a polyfill for older browsers, right below the examples.
- caperfee 12y agoIt's not quite so simple since JavaScript has the concept of array-like objects - basically objects with a length property and numeric keys (but which aren't arrays). From the Underscore documentation: "Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar". So basically this bug can lead to false positives when checking for array-like objects.