.split()

Breaks the string on which it called into an array of substrings, and returns the new array.

Syntax

Loading...

The separator (optional) describes the pattern where each split should occur. It may be a string or a regular expression. If not provided, the returned array will contain the entire string as its lone element.

Loading...

The limit (optional) determines the number of substring elements included in the array.

Examples

Split string into array of names:

Loading...

Limit the number of names in array to three:

Loading...

Split string without providing a separator argument:

Loading...

Split string on each character:

Loading...
Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy