Skip navigation

typeof method in JavaScript returns wrong value if you pass an array as parameter. To fix this, we can add isArray method to JavaScript’s native Array object. In future, if browser includes one such method, the below code will not break as it will use browser’s native code in that case.

This will be handy fix for typeof known bug for Arrays.

 * @author rajakvk <rajakvk(at)>
if (!Array.isArray) {
     * Returns true if an object is an array, false if it is not.
     * @name isArray
     * @methodOf Array
     * @param {*} value 
     * @returns {Boolean}
    Array.isArray  = function (value) {
        return === '[object Array]';



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: