774 shaares
10 private links
10 private links
1 result
tagged
raaaaah
['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. '7' is parsed as radix 1, which is NaN, '11' is parsed as radix 2, which is 3. '1' is parsed as the default radix 10, because its index 0 is falsy.
And so, the following code will work as intended:
['1', '7', '11'].map(numStr => parseInt(numStr));