43
rated 0 times
[
46]
[
3]
/ answers: 1 / hits: 15612
/ 12 Years ago, fri, january 25, 2013, 12:00:00
Possible Duplicate:
javascript - Array.map and parseInt
I saw this example of strange JavaScript behavior on twitter
['10','10','10','10','10'].map(parseInt)
evaluates to
[10, NaN, 2, 3, 4]
could somebody explain this behavior? I verified it in chrome and firebug
['10','10','10','10','10'].map(function(x){return parseInt(x);})
correctly returns an array of 10s as integers. Is this an improper use of map(), a bug with parseInt, or something else?
More From » functional-programming