split(" "); let word = myArray[1]; Try it Yourself » Split the characters, including spaces: const myArray = text.split(""); Try it Yourself » Use the limit parameter: const myArray = text.split(" ", 3); Try it Yourself » More examples below....
The split() Method The slice() Method The substring() Method Syntax string.substr(start, length) Parameters Parameter Description start Required.The start position.First character is at index 0. If start is greater than the length, substr() returns "".If start is negative, substr() counts ...
If the separator is omitted, the returned array will contain the whole string in index [0].If the separator is "", the returned array will be an array of single characters:Example var txt = "Hello"; // String txt.split(""); // Split in characters Try it Yourself » ...
Example Split the string, but keep the line breaks: txt = "Thank you for the music\nWelcome to the jungle"x = txt.splitlines(True) print(x) Try it Yourself » ❮ String Methods Track your progress - it's free! Log in Sign Up ...
Log in / Sign Up Create afreeW3Schools Account to Improve Your Learning Experience My Learning Track your learning progress at W3Schools and collect rewards Upgrade Become a PLUS user and unlock powerful features (ad-free, hosting, support,..) ...
text.split(" ")// Split on spaces text.split("|")// Split on pipe Try it Yourself » If the separator is omitted, the returned array will contain the whole string in index [0]. If the separator is "", the returned array will be an array of single characters: ...
About errors:help@w3schools.com × Java Stringjoin()Method ❮ String Methods Example Join strings with a space between them: String fruits = String.join(" ", "Orange", "Apple", "Mango"); System.out.println(fruits); ...
strrchr() Returns a pointer to the last occurrence of a character in a string strspn() Returns the length of a string up to the first character which is not one of the specified characters strstr() Returns a pointer to the first occurrence of a string in another string strtok() Splits ...
rsplit() Splits the string at the specified separator, and returns a list rstrip() Returns a right trim version of the string split() Splits the string at the specified separator, and returns a list splitlines() Splits the string at line breaks and returns a list startswith() Returns ...
lettext ="Visit Microsoft!"; letresult = text.replace("Microsoft","W3Schools"); Try it Yourself » A global replacement: lettext ="Mr Blue has a blue house and a blue car"; letresult = text.replace(/blue/g,"red"); Try it Yourself » ...