0

I know I can do this:

a = ['1', '2']
b = []
a.forEach(function(e) { b.push(parseInt(e)); })
b
>> [1, 2]

I want to learn what is wrong in this?

['1', '2'].map(parseInt)
>> [1, NaN]
Chakradar Raju
  • 2,691
  • 2
  • 26
  • 42
  • Also see my answer on [JavaScript: parseInt's radix mystery with Array.map](//stackoverflow.com/a/35180286) – Tushar Apr 05 '17 at 04:15

1 Answers1

0

You can do that in the following way using map() by passing Number:

var res = ['1', '2'].map(Number)
console.log(res);
Mamun
  • 66,969
  • 9
  • 47
  • 59