I have read in many answers that under circumstances radix
in parseInt
default to 10
.
I don't understand though, why I get the output I do below, where the strings
["1856", "1857", "1858"]
get parsed as:
[1856, NaN, 1]
I've set up the example below to check how parseInt
responds with different radix values. But none seem to match. What am I missing?
const ids = ["1856", "1857", "1858"];
const parsed = Array.from(new Array(20).keys())
.reduce((p, n) => ({
...p,
[n]: ids.map(x => parseInt(x, n)),
}))
console.log(ids.map(parseInt))
console.log(parsed)