English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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
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‹/›
All browsers fully support the split() method:
Method | |||||
split() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
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 |
Return value: | in the given stringseparatorString array split at each point |
---|---|
JavaScript Version: | ECMAScript 1 |
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]; // isTest 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‹/›