For example, there is a string:
var dataStr="1,2,3,4,5";
Now we need to split it into int type Array:
var dataIntArr=;
How to do it? There are many methods, here are two interesting ones:
var dataStr="1,2,3,4,5";//original string
var dataStrArr=dataStr. split(",");//Split into a string array
var dataIntArr=[];//Save the converted integer string
//Method 1 p>
dataStrArr.forEach(function(data,index,arr){
dataIntArr.push(+data);
});
console.log(dataIntArr);
//Method 2
dataIntArr=dataStrArr.map(function(data){
return +data;
});
console.log(dataIntArr);
To understand these two methods, you must understand the usage of map and forEach.