parseInt() takes to arguments, a string and a radix. I usually pass just the string I want converting as a number, you are passing both the string and the radix!
parseInt()
string
radix
map gives us the value and the index (and the actual array)
map
["10", "10", "10", "10"].map( (value,index) => ... )
By just doing .map(parseInt) parseInt is taking both the value and the index.
.map(parseInt)
parseInt
Basically the second iteration is parseInt('10',1) and returns NaN.
parseInt('10',1)
NaN
Finally, to test that that's what happens, the following would return "0: 10" "1: 10" "2: 10" "3: 10"
"0: 10" "1: 10" "2: 10" "3: 10"
function myFunc(value, i){ console.log(`${i}: ${value}`) } ["10", "10", "10", "10"].map(myFunc)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
parseInt()
takes to arguments, astring
and aradix
. I usually pass just the string I want converting as a number, you are passing both the string and the radix!map
gives us the value and the index (and the actual array)By just doing
.map(parseInt)
parseInt
is taking both the value and the index.Basically the second iteration is
parseInt('10',1)
and returnsNaN
.Finally, to test that that's what happens, the following would return
"0: 10" "1: 10" "2: 10" "3: 10"