Why does parseInt yield NaN with Array#map?

前端 未结 7 1462
故里飘歌
故里飘歌 2020-11-21 11:29

From the Mozilla Developer Network:

[1,4,9].map(Math.sqrt)

will yield:

[1,2,3]

Why then does this:

<
相关标签:
7条回答
  • 2020-11-21 12:01

    another (working) quick fix :

    var parseInt10 = function(x){return parseInt(x, 10);}
    
    ['0', '1', '2', '10', '15', '57'].map(parseInt10);
    //[0, 1, 2, 10, 15, 57]
    
    0 讨论(0)
提交回复
热议问题