String split() Method - Javascript String

Javascript examples for String:split


The split() method splits a string into an array of substrings, and returns the new array.

If "" is used as the separator, the string is split between each character.

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



Parameter Values

Parameter Description
separator Optional. character, or regular expression, for splitting the string. If omitted, the entire string will be returned
limit Optional. the number of splits, items after the split limit will not be included in the array

Return Value:

An Array, containing the splitted values

Split a string into an array of substrings:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/* w  ww.  j av a  2 s . c om*/
    var str = "How are you doing today?";
    var res = str.split("o");
    document.getElementById("demo").innerHTML = res;


Related Tutorials