4 ms·
That code snippet is also using a faulty technique for identifying an Array. Although it will work for the majority of cases, if you're using an array from a d
by dcherman 13y ago
That code snippet is also using a faulty technique for identifying an Array. Although it will work for the majority of cases, if you're using an array from a different iframe, the instanceof check will fail since the Array constructors are not the same.
You should be using Array.isArray ( ES5 compatible browsers ), or Object.prototype.toString.call( obj ) === '[object Array].
Lodash, Underscore, and jQuery all provide utility methods to do that comparison for you.
- inglor 13y agoShould probably do `.length` to detect it's iterable and not do a type check since that's an anti pattern anyway.
- underwater 13y agoThat would happily accept and iterate over a string, which wouldn't be desirable.