I am getting an array after some manipulation. I need to convert all array values as integers.
My sample code
var result_string = \'
const arrString = ["1","2","3","4","5"];
const arrInteger = arrString.map(x => Number.parseInt(x, 10));
Above one should be simple enough,
One tricky part is when you try to use point free function for map as below
const arrString = ["1","2","3","4","5"];
const arrInteger = arrString.map(Number.parseInt);
In this case, result will be [1, NaN, NaN, NaN, NaN] since function argument signature for map and parseInt differs
map expects -
(value, index, array)where as parseInt expects -(value, radix)