+ 9

JavaScript Map

Why does this code returns. (1, NaN, 3) let x = ["1", "7", "11"].map(parseInt) console.log(x)

14th Sep 2019, 7:01 PM
Qudusayo
Qudusayo - avatar
3 Respostas
+ 1
probably sth with binary. since 1b = 1d 11b = 3d 7 is not binary and cannot be converted so it becomes NaN
14th Sep 2019, 7:11 PM
Anton Böhler
Anton Böhler - avatar
+ 1
Actually parseInt can take one argument. Radix parameter is optional. The thing is you missed calback in map method, so add lambda function: ["1","7","11"].map(o => parseInt(o))
19th Sep 2019, 4:50 PM
Rustem Sharipov
Rustem Sharipov - avatar