['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.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With