Home  >  Article  >  Web Front-end  >  String split split()

String split split()

WBOY
WBOYOriginal
2016-09-03 00:00:102166browse

Knowledge explanation:

The

split() method splits a string into a string array and returns this array.

Grammar:

stringObject.split(separator,limit)

Parameter description:

Note: If you use the empty string ("") as a separator, each character in the stringObject will be split.

We will split the string in different ways:

Split the string using the specified symbol, the code is as follows:

<span style="color: #0000ff;">var</span> mystr = "www.imooc.com"<span style="color: #000000;">;
document.write(mystr.split(</span>".")+"<br>"<span style="color: #000000;">);
document.write(mystr.split(</span>".", 2)+"<br>");

Run result:

<span style="color: #000000;">www,imooc,com
www,imooc</span>

Split the string into characters, the code is as follows:

document.write(mystr.split("")+"<br>"<span style="color: #000000;">);
document.write(mystr.split(</span>"", 5));

Run result:

<span style="color: #000000;">w,w,w,.,i,m,o,o,c,.,c,o,m
w,w,w,.,i</span>

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