split Method (String) (JavaScript)

Split a string into substrings using the specified separator and return them as an array.


stringObj.split([separator[, limit]])  


Required. The String object or string literal to be split. This object is not modified by the split method.

Optional. A string or a Regular Expression object that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.

Optional. A value used to limit the number of elements returned in the array.

Return Value

The result of the split method is an array of strings split at each point where separator occurs in stringObj. The separator is not returned as part of any array element.


The following example illustrates the use of the split method.

var s = "The quick brown fox jumps over the lazy dog.";  
var ss = s.split(" ");  
for (var i in ss) {  

// Output:   
// The  
// quick  
// brown  
// fox  
// jumps  
// over  
// the  
// lazy  
// dog.  


Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: String Object

See Also

concat Method (String)
RegExp Object
Regular Expression Object
Regular Expression Syntax (JavaScript)
Scrolling, panning, and zooming sample app