The split() method in JavaScript is used to divide a string into an array of substrings based on a specified separator. It returns a new array without modifying the original string.

Syntax

string.split(separator, limit)
  • separator: The character, string, or regular expression used to determine where to split the string. If omitted or undefined, the entire string is returned as a single-element array.

  • limit: An optional integer that specifies the maximum number of substrings to include in the array. If provided, the method stops splitting after reaching this limit.

Key Examples

  • Split by space:

    "Hello World".split(" "); // Returns ["Hello", "World"]
  • Split by comma:

    "Jan,Feb,Mar".split(","); // Returns ["Jan", "Feb", "Mar"]
  • Split by empty string (UTF-16 code units):

    "Hi".split(""); // Returns ["H", "i"]

    ⚠️ Note: Using an empty string as a separator splits by UTF-16 code units, which can break surrogate pairs (e.g., emojis). Use the spread operator [...str] for correct character splitting.

  • Limit the number of splits:

    "a b c d".split(" ", 2); // Returns ["a", "b"]
  • Using regular expressions:

    "Hello1World2Test".split(/(\d)/); // Returns ["Hello", "1", "World", "2", "Test"]

Special Cases

  • If the string is empty and the separator is non-empty, returns [""].

  • If both string and separator are empty, returns [].

  • If the separator is a regular expression with capturing groups, the captured groups are included in the result array.

For more details, refer to the MDN Web Docs.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › split
String.prototype.split() - JavaScript | MDN
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - An invocation of this method of the form str.split(regex, n) yields the same result as the expression
Discussions

Adding to my Victron system
I installed this system in my temporary bus conversion 2 years ago and its been working great for us but we havent been running any a/c equipment with it yet. I only have the one Multiplus 2 24/3000 inverter/charger so far. I am moving forward on the final build of the bus and was looking for ... More on community.victronenergy.com
🌐 community.victronenergy.com
0
5 days ago
Split an array into 2 arrays based on conditions

It seems like you're looking for something complicated when something simple will suffice. Why not just:

let foo = names.filter(name => name.length == 4 && /^j/.test(name));
let bar = names.filter(name => name.length == 3 && /^b/.test(name));

If you absolutely must do it in one pass I suppose you can use reduce, but dear god is it ugly:

let result = names.reduce((output, name) => {
    if(name.length == 4 && /^j/.test(name)) output[0].push(name);
    else if(name.length == 3 && /^b/.test(name)) output[1].push(name);
    return output;
  }, [[], []]);

Are you really telling me that's any easier to read than the first version? Even a simple straightforward for-each loop is easier to read than that mess. I think you should explain more the context of how this will be used.

More on reddit.com
🌐 r/javascript
6
1
October 22, 2014
Can I split up large js files into separate files?
If you're just using vanilla in the browser, simply include each of the files you wish to use as script tags. Keep in mind however, that order matters. Anything that is declared in the first file will be available in the second and third, the second will be available to the third, etc. More on reddit.com
🌐 r/learnjavascript
22
5
July 1, 2019
TC39 proposal to split the language, js0 and jsSugar. Here we go..
I'm not worried, but only because the presentation is written in Comic Sans. Times New Roman would concern me tremendously, and a clean sans serif would be the kiss of death... More on reddit.com
🌐 r/javascript
65
61
October 22, 2024
🌐
W3Schools
w3schools.com › jsref › jsref_split.asp
JavaScript String split() Method
The split() method splits a string into an array of substrings.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › split() function in javascript
split() Function in JavaScript | How split() Function Works in JavaScript?
March 27, 2023 - JavaScript provides us many string methods to modify our current string according to the requirement we have split() method is one of them. Split function in JavaScript is used to split a string. So it splits the string into the array of substring ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Tutorial Gateway
tutorialgateway.org › home › javascript › javascript split string
JavaScript split String Function
March 25, 2025 - The JavaScript Split string function is used to split original string into array of substrings based on specified separator & return an array
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › slice
Array.prototype.slice() - JavaScript | MDN
The slice() method of Array instances returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
🌐
Educative
educative.io › answers › string-split-method-in-javascript
String split() method in JavaScript
The split() method in JavaScript enables us to break down a string into an array of (smaller) strings.
Find elsewhere
🌐
Medium
lalit-kushwah.medium.com › stop-using-split-to-split-string-with-space-in-javascript-7e1a1409cb0b
Stop using split(“ ”) to split string with space in javascript | by Lalit Kushwah | Medium
June 6, 2022 - Stop using split(“ ”) to split string with space in javascript Don’t believe in your eye Do you know about “No break space”? I am sure that you heard and used &nbsp in your HTML files and …
🌐
Victron Community
community.victronenergy.com › diy
Adding to my Victron system - DIY - Victron Community
5 days ago - I installed this system in my temporary bus conversion 2 years ago and its been working great for us but we havent been running any a/c equipment with it yet. I only have the one Multiplus 2 24/3000 inverter/charger so far. I am moving forward on the final build of the bus and was looking for ...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › split
JavaScript String split() - Divide String Into Array | Vultr Docs
November 11, 2024 - The JavaScript split() method is a versatile string function that divides a string into an ordered list of substrates by separating the strings into substrings.
🌐
GitHub
gist.github.com › nathancahill › fa0bf3b6ff0ed98f58604a6ef379e269
Split.js.md · GitHub
The programming goals of Split.js are to deliver readable, understandable and maintainable code, while at the same time manually optimizing for tiny minified file size, browser compatibility without additional requirements, graceful fallback (IE8 is supported) and very few assumptions about the user's page layout. Make sure all browsers handle this JS library correctly with ES5. More information here: Strict mode - JavaScript | MDN
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-split-a-string-once-in-javascript-3c3cfefe1321
How do you split a string once in JavaScript? | by John Au-Yeung | JavaScript in Plain English
June 10, 2024 - To split a string once in our JavaScript code, we can use the JavaScript string’s indexOf method with the JavaScript string’s slice method to find the index of the first instance of the separator and then do the slicing.
🌐
Career Karma
careerkarma.com › blog › javascript › javascript split: a step-by-step guide
JavaScript Split: A Step-By-Step Guide | Career Karma
December 1, 2023 - The JavaScript split() method divides a string into an array of substrings. These substrings are added to a new array.
🌐
Codecademy
codecademy.com › docs › javascript › strings › .split()
JavaScript | Strings | .split() | Codecademy
June 9, 2025 - In JavaScript, the .split() method returns a new array of substrings based on a given string.
🌐
Sololearn
sololearn.com › en › Discuss › 1562801 › solved-javascript-split-not-working
[SOLVED] JavaScript - split() not working | Sololearn: Learn to code for FREE!
Let's say you have a string: var result = "a,b,c" result.split(',') will split the string to an array of substrings a, b, and c.
🌐
Sentry
sentry.io › sentry answers › javascript › split a string in javascript
Split a string in JavaScript | Sentry
We can use JavaScript’s String.prototype.split() method. When called on a string, this will split the string at every instance of the provided separator, discard the separator, and return an array of substrings.
🌐
ReqBin
reqbin.com › code › javascript › wyqvcilw › javascript-split-string-example
How do I split a string in JavaScript?
February 10, 2023 - To split a string in JavaScript, you can use the string.split(separator, limit) method. The split() method splits the given string into an array of strings using "separator" as the delimiter.
🌐
Board Infinity
boardinfinity.com › blog › javascript-split
split() method in javascript | Board Infinity
August 9, 2025 - One of them is the split() method. A string can be divided using JavaScript's Split function. In order to give us a newly formed array, it splits the string into an array of substrings.