As in the title:
var doubleArray ;
if(!doubleArray || (doubleArray.lenght==&& doubleArray[0].length == 0 ){
return;
}
滿天的星座2017-05-18 11:03:34
var isArray = function(o) {
return Object.prototype.toString.call(o) === '[object Array]';
}
var doubleArray ;
if(!isArray(doubleArray) || !isArray(doubleArray[0]) || !doubleArray[0].length ){
return;
}
我想大声告诉你2017-05-18 11:03:34
Not exactly equivalent. . . . . . It is equivalent if you limit doubleArray to be an array within double. . .
undefined != true
null != true
It’s all normal, for the object==
其实是toPrimitive
之后再进行比较。
对于Array,其实就是toString
之后在进行比较,toString默认调用join
所以不论几重的数组,只要是空的,都是相当与“” == true
phpcn_u15822017-05-18 11:03:34
Combine the situation yourself. Just write it
function isEmpty(obj) {
if (!obj) {
return true;
}
if (Array.isArray(obj)) {
if (!obj.length) {
return true;
} else if (obj.length === 1 && Array.isArray(obj[0]) && obj[0].length === 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}