我發現一個空數組或一個數字就是一個數字。爲什麼一個數組中的數字只有一個數字?
本主題是不是真的爲這個特殊的情況下,我想一個解釋:Why does isNaN(" ") equal false
document.write(isNaN([1,2,3])); // true
document.write(isNaN([1,2,'abc'])); // true
document.write(isNaN(['abc'])); // true
// maybe explained through the above link
document.write(isNaN([])); // false
// but...
document.write(isNaN([1])); // false
document.write(isNaN([-3])); // false
document.write(isNaN([1234567])); // false
document.write(isNaN([-1.234])); // false
document.write(isNaN([[123]])); // false
document.write(isNaN(['1'])); // false
誰能告訴我,爲什麼它是有道理的?
是的,但這有什麼意義? – algorhythm 2014-11-24 13:13:37
@algorhythm檢查[MDN:isNaN()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN)和舊的全局'isNaN()'和'Number.isNaN()' – 2014-11-24 13:15:34
@algorhythm'isNaN':「[[如果參數強制爲'NaN',則返回'true',否則返回'false'。](http:// www。ecma-international.org/ecma-262/5.1/#sec-15.1.2.4)「 - 這裏的」強制「是指使用['ToNumber'](http://www.ecma-international.org/ecma-262 /5.1/#sec-9.3)對參數進行抽象操作,將字符串對象(如數組)和數字字符串(如1234567「',這是'[1234567]'的字符串化形式)。字符串形式的對象有一個逗號(如'「1,2,3」'),那麼該字符串不能被合理地轉換爲數字,所以它被強制轉換爲'NaN'。 – apsillers 2014-11-24 13:17:50