任何更好的转换想法

["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,但是您可以使用任何一种库来减少代码。

最佳答案

使用join()并拆分在一起。

arr.join(",").split(",");


Fiddle

关于javascript - 为数组中的每个条目分割逗号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22221740/

10-16 17:43