split

Converting a string to an array.

Examples

Split by Character

Splitting a CSV string into an array.

let text = "a,b,c,d,e";
const myArray = text.split(",");
console.log(myArray[0]); // "a"

Split by Space

Splitting sentences into words.

let text = "Hello World";
const arr = text.split(" ");
console.log(arr); // ["Hello", "World"]

Split into Characters

Splitting every character into an array.

let text = "Hello";
const arr = text.split("");
console.log(arr); // ["H", "e", "l", "l", "o"]

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.