Split a string only the at the first n occurrences of a delimiter

后端 未结 18 885
有刺的猬
有刺的猬 2020-12-24 06:22

I\'d like to split a string only the at the first n occurrences of a delimiter. I know, I could add them together using a loop, but isn\'t there a more straight forward appr

18条回答
  •  自闭症患者
    2020-12-24 06:38

    var s='Split this, but not this', a=s.split(','), b=a[0].split(' ');
    b.push(a[1]);
    alert(b);
    

    alerts ['Split', 'this', 'but not this']

提交回复
热议问题