字符串拼接

196 阅读1分钟

concat() 方法 字符串拼接 成一个新数组

  let str1 = 'hello'
  let str2 = 'word'
  const str = str1.concat(str2)
  console.log(str);  //['1', '2', '2', '3']
  

join() 方法 数组(字符串)转换成普通的 字符串

const att = ['200', 'f', 'dd', '方法']
//   1
const ad = att.join()
console.log(ad);  //200,f,dd,方法
//  2
const ad1 = att.join('')
console.log(ad1);  //200fdd方法
//  3
const ad2 = att.join('--')
console.log(ad2);  //200--f--dd--方法
总结: join() 就是把 数组字符串 转成 字符串   
括号里填啥  就代表用啥拼接字符串,
不填  join()      就默认以逗号拼接字符串
填单引号 join('') 就代表啥也不用直接转换字符串就行