javascript 字符串分割split()

落日映苍穹つ 2022-09-22 11:59 483阅读 0赞

字符串分割split()

split() 方法将字符串分割为字符串数组,并返回此数组。

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>无标题文档</title>
  6. <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>
  7. </head>
  8. <body>
  9. </body>
  10. </html>

结果:

  1. 86,010,85468578
  2. 8,6,-,0,1,0,-,8,5,4,6,8,5,7,8
  3. 8,6,-

发表评论

表情:
评论列表 (有 0 条评论,483人围观)

还没有评论,来说两句吧...

相关阅读