string.split(separator, limit) -- 将字符串分割为字符串数组,并返回此数组
- split,中文"分割"的意思
- 引用网址:http://www.dreamdu.com/javascript/string.split/
split函数语法
string
.
split
(
separator
,
limit
)
;
split函数参数
- separator -- 分隔符
- limit -- 可选参数,分割的次数,如果无此参数为不限制次数
split函数返回值
字符串数组
split函数示例
var
str
=
"
www.dreamdu.com
"
;
document
.
write
(
str
.
split
(
"
.
"
)
)
;
document
.
write
(
str
.
split
(
"
.
"
,
2
)
)
;
document
.
write
(
str
.
split
(
"
"
)
)
;
document
.
write
(
str
.
split
(
"
"
,
5
)
)
;
str
=
"
-www-dreamdu-com
"
;
document
.
write
(
str
.
split
(
"
-
"
)
)
;
结果:
www,dreamdu,com www,dreamdu w,w,w,.,d,r,e,a,m,d,u,.,c,o,m w,w,w,.,d ,www,dreamdu,com //返回的5个元素["", "www", "dreamdu", "com", ""]