Home > Web Front-end > HTML Tutorial > String split split()

String split split()

WBOY
Release: 2016-09-03 00:00:10
Original
2202 people have browsed it

Knowledge explanation:

The

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

Grammar:

stringObject.split(separator,limit)
Copy after login

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>");
Copy after login

Run result:

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

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));
Copy after login

Run result:

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template