Someone pointed this weird array result in JavaScript and I was hoping someone could explain why this happens.
If I have an array like so:
var arr = ["10", "10", "10", "10"];
And I try to map those "10"'s to integers like so:
arr.map(parseInt);
The result will be an array with the values: [10, NaN, 2, 3] (I ran all of this code in Chrome's console)
I expected the result to be: [10, 10, 10, 10]
I understand that JavaScript can parse integers from string into different numbering systems, like binary, which I think explains where the 2 and 3 three are coming from, kind of. But why would parseInt change to parsing them in different bases? Could someone please explain why this is the result I get?
parseint("10", 0) = 10, parseint("10", 1) = NaN , parseint("10", 2) = 2 , parseint("10", 3) = 3It was a simple misunderstanding of the functions.