任何更好的转换想法
["1","2","3,4","5","6","7,8,9"]
至["1","2","3","4","5","6","7","8","9"]
我想要实现的是创建少量代码,同时保持简单。
var arr=["1","2","3,4","5","6","7,8,9"];
var tmp=[];
for(var i=0,len=arr.length;i<len;i++){
tmp=tmp.concat(arr[i].split(","));
}
http://plnkr.co/edit/iJG2aPZ3JAFvsulxJDQe?p=preview
我使用了简单的js,但你可以使用任何类型的库来减少代码。
答案 0 :(得分:7)
答案 1 :(得分:4)
您可以就地进行替换:
for( var i=arr.length-1; i>=0; i--) {
arr.splice.apply(arr,[i,1].concat(arr[i].split(",")));
}