String split() method in JavaScript

The split() method in JavaScript enables us to break down a string into an array of (smaller) strings. Let’s jump directly into the code.


Example

string = "A-quick-brown-fox" //string to be split
array_of_strings = string.split("-") //The split() function
console.log(string) //note that the split function doesn't change the original string
console.log(array_of_strings)
Note that the breaking character is itself lost in the process
Note that the breaking character is itself lost in the process

The break character can be any available character. The codes below show the exact same task using space (" “) and empty (”") characters.

string = "A quick brown fox" //string to be split
array_of_strings = string.split(" ") //The split() function
console.log(string) //note that the split function doesn't change the original string
console.log(array_of_strings)
Using space character will divide the entire string into individual words

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved