首页 > 代码库 > js字符串函数之split()join()
js字符串函数之split()join()
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,e3 console.log(arr.join(""));//silence4 console.log(arr.join("."));//s.i.l.e.n.c.e5 console.log(arr.join("|"));//s|i|l|e|n|c|e
js字符串函数之split()join()
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。