It's because map
passes more arguments than just the array item into the callback function. You get:
callback(item, index, array)
Normally your function would just ignore the arguments it didn't need. But parseInt
accepts an optional second parameter:
parseInt(string, base)
for the first call, base
is the index
0
. That works okay because ECMAScript defines that base=0
is the same as omitting the argument, and consequently allows decimal, octal or hex (using decimal in this case).
For the second and third items, base
is 1
or 2
. It tries to parse the number as base-1 (which doesn't exist) or base-2 (binary). Since the first number in the string is a digit that doesn't exist in those bases, you get a NaN
.
In general, parseInt
without a base is pretty questionable anyway, so you probably want:
["655971", "2343", "343"].map(function(x) { return parseInt(x, 10) })