Split string once in javascript?

前端 未结 13 1005
南笙
南笙 2020-11-29 03:23

How can I split a string only once, i.e. make 1|Ceci n\'est pas une pipe: | Oui parse to: [\"1\", \"Ceci n\'est pas une pipe: | Oui\"]?

The

13条回答
  •  醉话见心
    2020-11-29 03:47

    one liner and imo, simpler:

    var str = 'I | am super | cool | yea!';
    str.split('|').slice(1).join('|');
    

    This returns " am super | cool | yea!"

提交回复
热议问题