Split the words:
let text = "How are you doing today?";
const myArray = text.split(" ");
Split the words, and return the second word:
let text = "How are you doing today?";
const myArray = text.split(" ");
let word = myArray[1];
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.
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.Split a string into characters and return the second character:
const myArray = text.split("");
Try it Yourself »Use a letter as a separator:
const myArray = text.split("o");
Try it Yourself »If the separator parameter is omitted, an array with the original string is returned:
const myArray = text.split();
Try it Yourself » Browser Supportsplit()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome Edge Firefox Safari Opera IE Yes Yes Yes Yes Yes YesTrack your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3