gistlib
To split a string into two strings in Javascript, there are a few ways to achieve this.
split()
index.tsxconst fullString = "Hello World"; const splitStrings = fullString.split(" "); console.log(splitStrings); // Output: ["Hello", "World"] 136 chars6 lines
const fullString = "Hello World"; const splitStrings = fullString.split(" "); console.log(splitStrings); // Output: ["Hello", "World"]
substr()
substring()
index.tsxconst fullString = "Hello World"; const firstString = fullString.substr(0, 5); // or const firstString = fullString.substring(0, 5); const secondString = fullString.substr(6); // or const secondString = fullString.substring(6); console.log(firstString); console.log(secondString); // Output: // "Hello" // "World" 316 chars13 lines
const fullString = "Hello World"; const firstString = fullString.substr(0, 5); // or const firstString = fullString.substring(0, 5); const secondString = fullString.substr(6); // or const secondString = fullString.substring(6); console.log(firstString); console.log(secondString); // Output: // "Hello" // "World"
gistlibby LogSnag