zoukankan      html  css  js  c++  java
  • JS字符串与数组的相互转换

    JS字符串与数组的相互转换

    在今天的工作中遇到一个问题,需要将string字符串转换为数组,在此记录一下。

    博客参考文章:https://www.cnblogs.com/smzd/p/11792878.html

    1、字符串转换为数组

    //customerLabelName="实施前、实施中、实施后",以split的字符进行切割
    var customerLabelNameResult = data[i].customerLabelName.split("、");
    var customerLabelColorNameResult = data[i].customerLabelColorName.split("、");
    //输出结果为:customerLabelNameResult:实施前,实施中,实施后
    console.log("customerLabelNameResult:" + customerLabelNameResult);
    for (let j = 0; j < customerLabelNameResult.length; j++) {
        html += "<div style='" + customerLabelColorNameResult[j] + "'>" + customerLabelNameResult[j] + "</div>"
    }
    

    2、数组转换为字符串

    //customerLabelNameResult=[实施前,实施中,实施后]
    var arrayToString = customerLabelNameResult.join(';');
    //输出结果为:arrayToString:实施前;实施中;实施后
    console.log("arrayToString:" + arrayToString);
    
    自我控制是最强者的本能-萧伯纳
  • 相关阅读:
    PE系统盘
    python常用方法手记
    python tushare
    idea导入导出java jar包
    javaweb项目配置tomcat启动
    window安装tomcat
    解决idea控制台乱码
    maven手记
    java redis常见问题
    java mysql常见问题
  • 原文地址:https://www.cnblogs.com/CF1314/p/13790363.html
Copyright © 2011-2022 走看看