This is kind of a challenge, as I'm sure there must be a better way to do this but I'm not able to find it.
Given a string, I want to split it into two strings by a given index. For instance:
input:
- string: "helloworld"
- index: 5
output: ["hello", "world"]
An easy way is to make two slices, but isn't there a more direct way like splitting by a regex or something? I would like to achieve my purpose with a single instruction.
The non-elegant way:
const str = "helloworld";
const [ str1, str2 ] = [ str.substring(0, 5), str.substring(5) ];