Limiting the times that .split() splits, rather than truncating the resulting array

后端 未结 8 1525
耶瑟儿~
耶瑟儿~ 2020-12-11 01:58

Really, pretty much what the title says.

Say you have this string:

var theString = \"a=b=c=d\";

Now, when you run theString

8条回答
  •  一整个雨季
    2020-12-11 02:50

    const theString = "a=b=c=d";
    const [first, ...rest] = theString.split("=");
    const second = rest.join("=")
    console.log(first, second)

    If you are using ECMA 2015, you just need 2 lines.

提交回复
热议问题