2018-06-14 join 和 split

2018-06-14  本文已影响0人  Mo_ham_med

区别

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('  '));
       
       
      
上一篇 下一篇

猜你喜欢

热点阅读