Home > Article > Web Front-end > String split split()
Knowledge explanation:
Thesplit() method splits a string into a string array and returns this array.
stringObject.split(separator,limit)
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>