【问题标题】:How we can convert an string of array to Array in JavaScript? [duplicate]我们如何在 JavaScript 中将数组字符串转换为数组? [复制]
【发布时间】:2022-08-05 21:28:12
【问题描述】:

例子 :

Input = \'[1,2,3]\' // 字符串类型

预期输出 = [1,2,3] //typeof 数组

    标签: javascript arrays string


    【解决方案1】:

    使用 JSON.parse 将字符串解析为数组/对象

    let myArray = JSON.parse(input)
    

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 2016-03-02
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      • 2015-10-23
      相关资源
      最近更新 更多