Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is ['1','2','3'].map(parseInt) result [duplicate]

Tags:

People also ask

Why 1 7 11 map parseInt returns 1 NaN 3 in Javascript?

['1', '7', '11']. map(parseInt) doesn't work as intended because map passes three arguments into parseInt() on each iteration. The second argument index is passed into parseInt as a radix parameter. So, each string in the array is parsed using a different radix.

What is the second argument of parseInt?

Javascript parseInt() is an inbuilt method that converts the string into an integer (a whole number). It accepts the two arguments. The first argument is the string, which needs to convert and the second argument is called the radix.


['1','2','3'].map(parseInt)

return [1, NaN, NaN]

I don't know why? In my opinion is like this:

['1','2','3'].map(function(i){return parseInt(i,10)})

return [1, 2, 3]

======================================================
and other
['1','2','3'].map(parseFloat)
return [1, 2, 3]