考虑以下几点:阵图和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