字符串分割split()
split() 方法将字符串分割为字符串数组,并返回此数组。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script type="text/javascript">
var mystr="86-010-85468578";
document.write(mystr.split('-')+ "<br />"); //以‘-’分割字符串;
document.write(mystr.split('')+ "<br />"); //将字符串的每个字符分割;
document.write(mystr.split('',3)); //将字符串的每个字符分割,分割3次;
</script>
</head>
<body>
</body>
</html>
结果:
86,010,85468578
8,6,-,0,1,0,-,8,5,4,6,8,5,7,8
8,6,-