Convert array of string javascript to array of integer javascript
问题 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? 回答1: Map it to the Number function: var array = ["1", "2", "3", "4", "5"]; array = array.map(Number); array; // [1, 2, 3, 4, 5] 回答2: The map() method creates a new array with the results of calling a provided function on every element in this array. The unary + acts more like parseFloat since it also accepts decimals. Refer this Try this snippet: var array = ["1", "2", "3"