如何判断是否是数组?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]'
}
}

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论