str=”1+2*3*2/4-10*2”;转化为:[“1”, “+”, 6, ““, “2”, “/”, “4”, “-“, “10”, ““, “2”]
直接代码:
var arr=str.split("");
for (var i = 0; i < arr.length; i++) {
if(arr[i]=="*" || arr[i]=="/" || arr[i]=="+" ||arr[i]=="-"){ //如果是乘法或者除法的时候
arr[i-1]=arr[i-1]+",";
arr[i+1]=","+arr[i+1];
}
}
var newarr=arr.join('').split(',');