【问题标题】:Convert raw string to array [duplicate]将原始字符串转换为数组[重复]
【发布时间】:2019-11-30 10:31:10
【问题描述】:

我需要在我的逻辑下方的 javascript 中将原始字符串转换为 json 数组

原文:

"[template1,template2]";

例外:

"["template1","template2"]";

【问题讨论】:

  • 你有没有尝试过?如果是,请发布该代码

标签: javascript json


【解决方案1】:

使用slice 检索方括号之间的文本,然后使用split

const input = "[template1,template2]";

const arr = input.slice(1, -1).split(',');
console.log(arr);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多