JavaScript split() Method

Definition and Usage

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


stringObject.split(separator, howmany)

Parameter Description
separator Required. Specifies the character, regular expression, or substring that is used to determine where to split the string
howmany Optional. Specify how many times split should occur. Must be a numeric value

Tips and Notes

Note: If an empty string ("") is used as the separator, the string is split between each character.


In this example we will split up a string in different ways:

<script type="text/javascript">
var str="How are you doing today?";
document.write(str.split(" ") + "<br />");
document.write(str.split("") + "<br />");
document.write(str.split(" ",3));

The output of the code above will be:

H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
JavaScript split() Method Reviewed by 1000sourcecodes on 20:58 Rating: 5
Powered by Blogger.