String.prototype.split
Divides a string into an ordered list of substrings and returns them as an array
Syntax
string.split(separator, limit?)Parameters
| Parameter | Type | Description |
|---|---|---|
| separator | string | RegExp | Pattern describing where each split should occur |
| limit | number | Maximum number of substrings to include |
Return Value
An array of strings
Examples
const str = 'Hello World Foo';
console.log(str.split(' ')); // ['Hello', 'World', 'Foo']const csv = 'name,age,city';
const fields = csv.split(',');
console.log(fields); // ['name', 'age', 'city']const str = 'camelCaseString';
const words = str.split(/(?=[A-Z])/);
console.log(words); // ['camel', 'Case', 'String']Understanding String.prototype.split
The String.prototype.split method in JavaScript divides a string into an ordered list of substrings and returns them as an array. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.
The method signature is string.split(separator, limit?). It accepts 2 parameters: separator, limit. When called, it returns an array of strings. Understanding when and how to use split() helps you write more expressive, readable code.
Common use cases for String.prototype.split include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-join, string-slice, string-match, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for String.prototype.split is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Array.prototype.joinCreates and returns a new string by concatenating all elements in an array, separated by commas or a specified separator
String.prototype.sliceExtracts a section of a string and returns it as a new string, without modifying the original string
String.prototype.matchRetrieves the result of matching a string against a regular expression
More String Methods
Other methods in the String object
Related Tools
More String Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.