Skip to content

Instantly share code, notes, and snippets.

@kesla
Created August 17, 2012 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kesla/3378547 to your computer and use it in GitHub Desktop.
Save kesla/3378547 to your computer and use it in GitHub Desktop.
.map(parseInt) fails
['1', '2'].map(parseInt)
// output [1, NaN]
['1', '2'].map(Number)
// output [1, 2]
Why?
@dslming
Copy link

dslming commented Aug 6, 2018

  1. when parseInt() receive second param, and this param is illegal, the result is fails.
  2. Function map() will send 3 params to parseInt, is value, index and array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment