array like objects

Breton Slivka zen at zenpsycho.com
Mon Dec 7 18:29:53 PST 2009


The one that I use is

function isArrayLike(i){
    return (typeof i !=="string") && i.length !== void (0);
}

It might not be perfect, but it allows me to make certain assumptions
about the input that are useful enough. Keep in mind that an Array may
have a length of 5, and all those values are undefined, so  {length:4}
could be used as a valid arrayLike, and that seems reasonable to me.


More information about the es-discuss mailing list