Home  >  Article  >  Web Front-end  >  Instructions on how to use split function in js_javascript skills

Instructions on how to use split function in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:06:571589browse

split
split is the opposite of join and is used to split a string into a string array.
stringObject.split(a,b) This is Its syntax.

a is required. Decide to split from a.
b is not required, it is optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.

Note that a itself is not included in the returned array;

Tips and Notes
Note: If an empty string ("") is used as a, stringObject will be split between each character.
Note: The operation performed by String.split() is the opposite of the operation performed by Array.join.

Example
var str="Hello World!";
document.write(str.split("") "
");
document .write(str.split(" ") "
");
document.write(str.split("",3) "
");

Return
H,e,l,l,o, ,W,o,r,l,d,!
Hello,World!
H,e,l

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn