关于javascript:如何判断是否是数组How-to-judge-whether-it-is-a-array

如何判断是否是数组?

1、es6 中退出了新的判断办法:

if(Array.isArray(value)){
    return true;
}

2、在思考兼容性的状况下能够用toString的办法:

if(!Array.isArray){
    Array.isArray = function(arg){
        return Object.prototype.toString.call(arg)==='[object Array]'
    }

}

How to judge whether it is a array ?

1、 There are some judgment methods has been added to es6 :

if(Array.isArray(value)){
    return true;
}

2、You can use the function of toString that consider when the situation of compatibility is considered.

if(!Array.isArray){
    Array.isArray = function(arg){
        return Object.prototype.toString.call(arg)==='[object Array]'
    }

}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理