Reputation: 451
I am trying to extract the string which is like
var str = "[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]"
Desired ouput
a = "/home/dev/servers"
b = "e334ffssfds245fsdff2f"
Upvotes: 0
Views: 67
Reputation: 20039
Using JSON.parse()
let [a, b] = JSON.parse("[\"/home/dev/servers\", \"e334ffssfds245fsdff2f\"]")
console.log(a)
console.log(b)
Upvotes: 0
Reputation: 2190
Here you are:
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);
Upvotes: 2
Reputation: 78
The following will work fine for you.
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];
Upvotes: 2