美文网首页
2018-06-14 join 和 split

2018-06-14 join 和 split

作者: Mo_ham_med | 来源:发表于2018-06-14 10:45 被阅读0次

区别

join() 把数组转换为字符串。
括号里些什么就用什么分割。
因为数组 本身就是用的 , 号 隔开的。
意思 就是替换 ,


      var arr = [1,2,6,3,5,4,8];
      console.log(arr.join())

split() 把字符串转化为数组
括号里写什么 就 从 指定的位置 分成数组
如果 写 空字符串的话,每个字符之间 都会被分割。


      var str = 'abcdefg sdsfdfdf';

      console.log(str)
      console.log(str.split('  '));
       
       
      

相关文章

网友评论

      本文标题:2018-06-14 join 和 split

      本文链接:https://www.haomeiwen.com/subject/ftweeftx.html