Split on every second comma in javascript

后端 未结 6 1106
余生分开走
余生分开走 2021-01-18 01:05

For string:

\'29 July, 2014, 30 July, 2014, 31 July, 2014\'

How can I split on every second comma in the string? So that my results are:

6条回答
  •  余生分开走
    2021-01-18 01:37

    Not sure if you can do it in a one-liner, but a workaround would be to split on every comma then join consecutive values.

    ex:

    var str = '29 July, 2014, 30 July, 2014, 31 July, 2014';
    var list = str.split(",");
    var list2 =[];
    for (var i=0;i

提交回复
热议问题