could someone explain why I get this weird result by executing following code?
'1.0.0.0'.split('.').map(parseInt);
Output:
[1, NaN, 0, 0]
could someone explain why I get this weird result by executing following code?
'1.0.0.0'.split('.').map(parseInt);
Output:
[1, NaN, 0, 0]
parseInt has a second argument that is the radix. map is passing three arguments: currentValue, index and the array. That means that the index of the number is used as the radix. Try this instead:
'1.0.0.0'.split('.').map(function(s) {return parseInt(s);});