split() 方法用於把一個字元串分割成字元串數組。<script type="text/javascript"> var str="How are you doing today?" document.write(str.split(" ") + "<br />")document.write( ...
split() 方法用於把一個字元串分割成字元串數組。
<script type="text/javascript">
var str="How are you doing today?"
document.write(str.split(" ") + "<br />")
document.write(str.split("") + "<br />")
document.write(str.split(" ",3))
輸出:
How,are,you,doing,today?
H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
How,are,you
"2:3:4:5".split(":") //將返回["2", "3", "4", "5"]
"|a|b|c".split("|") //將返回["", "a", "b", "c"]