JavaScript String split() Method | javascript string split
ExamplesSplitthewords:lettext="Howareyoudoingtoday?";constmyArray=text.split("");TryitYourself»[1]Splitthewords,andreturnthesecondword:lettext="Howareyoudoingtoday?";constmyArray=text.split("");letword=myArray[1];TryitYourself»[2]Splitthecharacters,includingspaces:constmyArray=text.split("");TryitYourself»[3]Usethelimitparameter:constmyArray=text.split("",3);TryitYourself»[4]Moreexamplesbelow.DescriptionThesplit()methodsplitsastringintoanarrayofsubstrings.Thesplit()methodreturnsthenewarray.T...
ExamplesSplit the words:
let text = "How are you doing today?";const myArray = text.split(" ");
Try it Yourself »[1]Split the words, and return the second word:
let text = "How are you doing today?";const myArray = text.split(" ");let word = myArray[1];
Try it Yourself »[2]Split the characters, including spaces:
const myArray = text.split("");
Try it Yourself »[3]Use the limit parameter:
const myArray = text.split(" ", 3);
Try it Yourself »[4]More examples below.
DescriptionThe split() method splits a string into an array of substrings.
The split() method returns the new array.
The split() method does not change the original string.
If (" ") is used as separator, the string is split between words.
Syntaxstring.split(separator, limit)
Parameters Parameter Description separator Optional.A string or regular expression to use for splitting. If omitted, a...