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

后端 未结 18 890
有刺的猬
有刺的猬 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:56

    In my case this solves my problem:

    const splitted = path.split('/')
    const core = splittedPath.slice(0, 2)
    const rest = splittedPath.slice(2).join('/')
    const result = [...core, rest]
    

提交回复
热议问题