As in the title:
var doubleArray ; if(!doubleArray || (doubleArray.lenght==&& doubleArray[0].length == 0 ){ return; }
var isArray = function(o) { return Object.prototype.toString.call(o) === '[object Array]'; } var doubleArray ; if(!isArray(doubleArray) || !isArray(doubleArray[0]) || !doubleArray[0].length ){ return; }
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
==
toPrimitive
toString
join
“” == true
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; } }
Not exactly equivalent. . . . . . It is equivalent if you limit doubleArray to be an array within double. . .
It’s all normal, for the object
==
其实是toPrimitive
之后再进行比较。对于Array,其实就是
toString
之后在进行比较,toString默认调用join
所以不论几重的数组,只要是空的,都是相当与
“” == true
Combine the situation yourself. Just write it