考慮以下幾點:陣圖和parseInt函數愁楚
> '10.0.0.1'.split('.').map(parseInt)
[10, NaN, 0, 1]
爲什麼不是輸出,而不是:或者使用parseFloat
> x = '10.0.0.1'.split('.');
["10", "0", "0", "1"]
> x[1] == x[2]
true
:
[10, 0, 0, 1]
儘管下面拿着真確實給了我想要的輸出;但是我覺得我錯過了一些關鍵的東西。
編輯:'10.0.0.1'.split('.').map(function(x) { return parseInt(x); })
按預期工作。
EDIT2:我使用Chrome版本26.0.1410.64,但這也發生在我本地的node.js副本中。
http://stackoverflow.com/questions/262427/javascript-arraymap-and-parseint http://stackoverflow.com/questions/8594699/map-parseint-strange-results – 2013-04-23 00:39:47