cuipingzhao

1.字符串转为数组

let str = \'helloworld\'
let tempStr = str.split(\'\') 
let arrStr = [...str]
console.log(tempStr) //["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
console.log(arrStr) //["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]

2.数组转字符串

let arrList = ["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
let stringOne = arrList.join(\'\')
console.log(stringOne) //helloworld
toString将数组的每个元素都转换为字符串。当每个元素都被转换为字符串时,使用逗号进行分隔,以列表的形式输出这些字符串。
let arrList = ["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
let stringTwo = arrList.toString()
console.log(stringTwo) //h,e,l,l,o,w,o,r,l,d
// 全局替换
let tempString = stringTwo.replace(/,/g,\'\')
console.log(tempString) //helloworld

  

分类:

技术点:

相关文章:

  • 2021-04-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-01-26
  • 2022-12-23
  • 2021-11-08
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-08-15
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案