When I execute the following statements:
var string = "1 1 1 1 1 1 0 1 1"
console.log(string)
var strings = string.split(" ")
console.log(strings)
var numbers1 = strings.map(parseInt)
console.log(numbers1)
var numbers2 = strings.map(function(i){ return parseInt(i, 10) })
console.log(numbers2)
I get the following output in the console:
1 1 1 1 1 1 0 1 1
["1", "1", "1", "1", "1", "1", "0", "1", "1"]
[1, NaN, 1, 1, 1, 1, 0, 1, 1]
[1, 1, 1, 1, 1, 1, 0, 1, 1]
I wonder why the second element in numbers1
is NaN. Why does it work on all the other elements except this one?