When try something like this in JavaScript ['10','10','10'].map(parseInt)
You will get this is as a result: [ 10, NaN, 2 ]
Why does this happen?
When try something like this in JavaScript ['10','10','10'].map(parseInt)
You will get this is as a result: [ 10, NaN, 2 ]
Why does this happen?
parseInt
is often used with one argument, but takes two.
The first is an expression and the second is the radix.
To the callback function, Array.prototype.map passes 3 arguments to parseInt
: the element, the index, the array.
The third argument is ignored by parseInt
, but not the second one, hence the possible confusion.