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

      

  • 相关阅读:
    MongoDB
    Flask-Migrate
    Flask-Script
    Flask-SQLAlchemy
    SQLAlchemy
    DBUtils
    依存句法分析
    如何将本地的jar包上传到maven本地仓库中
    git使用手册
    中文网页编解码问题
  • 原文地址:https://www.cnblogs.com/cuipingzhao/p/15318840.html
Copyright © 2011-2022 走看看