Easy Tutorial
❮ Js Datatypes Js Ex Objects ❯

JavaScript split() Method

JavaScript String Object

Example

Split a string into an array of substrings:

n Output the values of an array:


Definition and Usage

The split() method is used to split a string into an array of substrings.

Tip: If an empty string ("") is used as the separator, the string is split between each character.

Note: The split() method does not change the original string.


Browser Support

All major browsers support the split() method.


Syntax

Parameter Values

Parameter Description
separator Optional. A string or regular expression to split the string Object at the specified position.
limit Optional. This parameter specifies the maximum length of the returned array. If set, the array will not contain more substrings than this parameter specifies. If not set, the entire string will be split without considering its length.

Return Value

Type Description
Array An array of strings. This array is created by splitting the string Object at the boundaries specified by the separator. The substrings in the returned array do not include the separator itself.

Technical Details

| JavaScript Version: | 1.1 | | --- | --- |


More Examples

Example

Omit the split parameter:

n Output the result of the array values:

Example

Split each character, including spaces:

n Output the result of the array values:

Example

Use the limit parameter:

n Output the values of 3 arrays:

Example

Use a single character as the separator:

n Output the result of the array values:


JavaScript String Object

❮ Js Datatypes Js Ex Objects ❯