Export (0) Print
Expand All

split Method (String) (JavaScript)

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

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

stringObj

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

separator

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.

limit

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

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) {
    document.write(ss[i]);
    document.write("<br/>");
}

// 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 (JavaScript)

Show:
© 2014 Microsoft