English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JS DOM Reference Manual

 JavaScript String Object

split()JavaScript String split() Method

separator The method splits the string into an array of substrings and then returns the new array.

The parameter determines where each split should be made.separatorIf a blank string ("") is used as

Syntax:

string.split(separator, limit)
var str =39;Air Pollution is the introduction of chemicals to the atmosphere.39;;
var arr = str.split(" ");
Test and see‹/›

Browser compatibility

All browsers fully support the split() method:

Method
split()IsIsIsIsIs

Parameter value

ParameterDescription
separator(Required) Specify a character or regular expression to indicate where each split should occur.
limit(Optional) An integer specifying the number of splits, items after the split limit will not be included in the array

Technical Details

Return value:in the given stringseparatorString array split at each point
JavaScript Version:ECMAScript 1

More Examples

Now we arearrA new array has been added to the variable, and we can access each element using an index:

arr[0];   // Air
arr[2];   // is
Test and see‹/›

Use "i" as a separator:

var str =39;Air Pollution is the introduction of chemicals to the atmosphere.39;;
var arr = str.split("i");
Test and see‹/›

Split each character:

var str =39;Air Pollution is the introduction of chemicals to the atmosphere.39;;
var arr = str.split("");
Test and see‹/›

Return a limited number of splits:

var str =39;Air Pollution is the introduction of chemicals to the atmosphere.39;;
var arr = str.split(" ", 4);
Test and see‹/›

 JavaScript String Object