zoukankan      html  css  js  c++  java
  • 数据格式转换的操作

    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

      

  • 相关阅读:
    UVA11375
    uva11806(容斥原理)
    uva10325(容斥原理)
    hdu4135(容斥原理)
    CF798
    多线程
    (转载)SVN 提交操作缩写(A D M R) .
    上不了网,如何判断
    (转载)myeclipse项目名称重命名
    mysql模糊查询
  • 原文地址:https://www.cnblogs.com/cuipingzhao/p/15318840.html
Copyright © 2011-2022 走看看