配列かどうかをどう判断しますか?How to judge whether it is a array ?
823 ワード
配列かどうかをどう判断しますか?
1、
2、互換性を考慮した場合、
How to judge whether it is a array ?
1、 There are some judgment methods has been added to
2、You can use the function of
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]'
}
}