Easy Tutorial
❮ Jsref Indexof Array Jsref Getmilliseconds ❯

JavaScript split() Method

JavaScript String Object

Example

Divide a string into an array of strings:

n Output the values of an array:


Definition and Usage

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

Tip: If an empty string ("") is used as the separator, each character in the stringObject will be separated.

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, the stringObject is split at the specified location by this parameter.
limit Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substrings will not exceed the array specified by this parameter. If this parameter is not set, the entire string will be split, regardless of its length.

Return Value

Type Description
Array An array of strings. This array is created by splitting the stringObject into substrings at the boundaries specified by 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

❮ Jsref Indexof Array Jsref Getmilliseconds ❯