码迷,mamicode.com
首页 > Web开发 > 详细

js字符串函数之split()join()

时间:2014-12-26 12:34:04      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

split方法用于把一个字符串切割成字符串数组,与join相反

一个参数表示以该参数为切割点,

1     var str="silence‘s world";
2     console.log(str.split(" "));// ["silence‘s", "world"]
3     console.log(str.split("‘"));// ["silence", "s world"]
4     console.log(str.split(""));//["s", "i", "l", "e", "n", "c", "e", "‘", "s", " ", "w", "o", "r", "l", "d"]
5   //两个参数时,后一个参数表示长度
6     console.log(str.split("‘",1));// ["silence"]
7     console.log(str.split("",5));// ["s", "i", "l", "e", "n"]

join方法用于将数组连接成字符串

1 var arr=["s","i","l","e","n","c","e"]
2     console.log(arr.join(","));//s,i,l,e,n,c,e
3     console.log(arr.join(""));//silence
4     console.log(arr.join("."));//s.i.l.e.n.c.e
5     console.log(arr.join("|"));//s|i|l|e|n|c|e

 

js字符串函数之split()join()

标签:

原文地址:http://www.cnblogs.com/MissBean/p/4186331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!