Javascript isArray() : Check if an element/object is an Array

The isArray() function over at BreakingPar.com looks great at first, but unfortunately does not work in Safari. This one here does work ;)

// X-Browser isArray(), including Safari
function isArray(obj) {
    return obj.constructor == Array;
}
Elsewhere, javascript ,

3 Responses to Javascript isArray() : Check if an element/object is an Array

  1. Mark says:

    Works great, thanks!

  2. doggy says:

    awesome, that’s what i’ve been looking for :)

  3. shrewman says:

    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!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>