我正在尝试提取像这样的字符串
var str = "[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]"
期望的输出
a = "/home/dev/servers"
b = "e334ffssfds245fsdff2f"
答案 0 :(得分:2)
以下内容适合您。
var str = "[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]";
var foo = JSON.parse(str); //Parse the JSON into an object.
var a = foo[0];
var b = foo[1];
答案 1 :(得分:2)
您在这里:
const str = "[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]";
const object = JSON.parse(str);
const a = object[0];
const b = object[1];
console.log(a);
console.log(b);
答案 2 :(得分:0)
使用JSON.parse()
let [a, b] = JSON.parse("[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]")
console.log(a)
console.log(b)