String split() Method - Javascript String

Javascript examples for String:split

Description

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.

Syntax

string.split(separator,limit)

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>
<html>
<body>

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

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

<script>
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;
}
</script>

</body>
</html>

Related Tutorials