How to detect whether an object is an array Back

To justice whether an object is an array, you may have so much methods, but the most proper one should be like this:

function isArray(obj) {
    return Array.isArray ? Array.isArray(obj) : Object.prototype.toString.call(obj) === '[object Array]';
}

Problems of other methods, like only using Array.isArray will have some side effects under IE 8, have been discussed in here.

results matching ""

    No results matching ""