I have an array,
var array = ["1","2","3","4","5"];
then i need to convert to
var array = [1,2,3,4,5];
How can i convert?
Match it with the Number function:
Number
var array = ["1", "2", "3", "4", "5"]; array = array.map(Number); array; // [1, 2, 3, 4, 5]
The map () method creates a new array with the results of calling the provided function for each element in this array.Unary + acts more like parseFloat, since it also accepts decimal numbers.
The map () method creates a new array with the results of calling the provided function for each element in this array.
Unary + acts more like parseFloat, since it also accepts decimal numbers.
Contact
Try this snippet:
var array = ["1", "2", "3", "4", "5"]; array = array.map(function(item) { return +item; }); console.log(array);