判断一个变量是否是Array类型

instanceof 操作符  和  对象的constructor 属性 也可以判断,如: alert(arr.constructor === Array); // true , 但是不够好。

推荐 Object.prototype.toStringArray.isArray() 的组合使用

function isArray(value){
    if(typeof Array.isArray === "function"){
        return Array.isArray(value);
    }else{
        return Object.prototype.toString.call(value) === "[object Array]";
    }
}

猜你喜欢

转载自www.cnblogs.com/solorhythm/p/10496595.html