The isArray()
function over at BreakingPar.com looks great at first, but unfortunately does not work in Safari. This one here does work π
// Cross-Browser isArray(), including Safari
function isArray(obj) {
return obj.constructor == Array;
}
Works great, thanks!
awesome, that’s what i’ve been looking for π
Thank you for this, it was the quick fix I needed, and it sorted the afore mentioned Webkit issue that the BreakingPar.com version had.
However, I found that if ‘obj’ was undefined. The code would break and an error would be returned.
To fix this, I simply added to you code to safeguard it from this:
function isArray(obj) {
if (typeof obj != “undefined”) {
return obj.constructor == Array;
} else
return false;
}
Hope this helps someone else!
Or even simpler than shrewman example:
function isArray(obj) {
return obj && obj.constructor == Array;
}
Sweet I now know how to test an object with . constructor thanks! +1
function isArray(v) {
return Object.prototype.toString.call(v) === ‘[object Array]’;
}