It's easy if your browser has Object.keys or nobody has mucked around with Object.prototype. As for the ease of testing if something is an array, figuring out if something is an array is relatively easy but array like objects like arguments and domlist are where length checking comes from.
Most browsers can do a for..in. At least for me there is no browser in existence that I care about that doesn't have that :)
nobody has mucked around with Object.prototype
That's just what object.hasOwnProperty(key) is for. An annoying extra check but not a big deal.
As for the ease of testing if something is an array, figuring out if something is an array is relatively easy but array like objects like arguments and domlist are where length checking comes from.
There is an incredibly limited list; I'd just check for those few items instead of relying on a property existing that other objects could use but I digress.
Most browsers can do a for..in. At least for me there is no browser in existence that I care about that doesn't have that :)
then why are you using the underscore/lodash/jquery method, it's main advantage (besides working on array like objects) is compatibility for older browsers..
I'm, btw, on your side here and just use Object.keys and move on for objects and use a while loop for array like objects.
then why are you using the underscore/lodash/jquery method, it's main advantage (besides working on array like objects) is compatibility for older browsers..
Oh I'm not my point was it's not really necessary anymore. It's been so long since browsers didn't have support for these kinds of things I can't imagine the compatibility is that important anymore except in say corporate environments.
Comments
It's easy if your browser has Object.keys or nobody has mucked around with Object.prototype. As for the ease of testing if something is an array, figuring out if something is an array is relatively easy but array like objects like arguments and domlist are where length checking comes from.
Most browsers can do a for..in. At least for me there is no browser in existence that I care about that doesn't have that :)
That's just what object.hasOwnProperty(key) is for. An annoying extra check but not a big deal.
There is an incredibly limited list; I'd just check for those few items instead of relying on a property existing that other objects could use but I digress.
then why are you using the underscore/lodash/jquery method, it's main advantage (besides working on array like objects) is compatibility for older browsers..
I'm, btw, on your side here and just use Object.keys and move on for objects and use a while loop for array like objects.
Oh I'm not my point was it's not really necessary anymore. It's been so long since browsers didn't have support for these kinds of things I can't imagine the compatibility is that important anymore except in say corporate environments.