split Method See Also concat Method | RegExp Object | Regular Expression Object | Regular Expression Syntax | String Object MethodsApplies To: String Object Requirements Version 3 Returns the array of strings that results when a string is separated into substrings.stringObj.split([separator[, limit]]) Arguments stringObj Required. The String object or literal to be split. This object is not modified by the split method. separator Optional. A string or an instance of a Regular Expression object identifying one or more 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. Res 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.Example The following example illustrates the use of the split method.function SplitDemo(){ var s, ss; var s = "The rain in Spain falls mainly in the plain."; // Split at each space character. ss = s.split(" "); return(ss); }
str = "北京,郑州,武汉,杭州,上海" arr = str.split(",") for (var i=0;i<arr.length;i++) alert(arr[i]);alert(arr.join(","));
See Also
concat Method | RegExp Object | Regular Expression Object | Regular Expression Syntax | String Object MethodsApplies To: String Object
Requirements
Version 3
Returns the array of strings that results when a string is separated into substrings.stringObj.split([separator[, limit]])
Arguments
stringObj
Required. The String object or literal to be split. This object is not modified by the split method.
separator
Optional. A string or an instance of a Regular Expression object identifying one or more 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.
Res
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.Example
The following example illustrates the use of the split method.function SplitDemo(){
var s, ss;
var s = "The rain in Spain falls mainly in the plain.";
// Split at each space character.
ss = s.split(" ");
return(ss);
}
arr = str.split(",")
for (var i=0;i<arr.length;i++)
alert(arr[i]);alert(arr.join(","));