I have a list detected as a string like this one:
var list = "['one', 'two', 'three']"
Is there a way to turn this into an array:
var real_list = ['one', 'two', 'three']
Edit: But I can't change the quotation marks of var list.
I have a list detected as a string like this one:
var list = "['one', 'two', 'three']"
Is there a way to turn this into an array:
var real_list = ['one', 'two', 'three']
Edit: But I can't change the quotation marks of var list.
Try Using
var list = "['one', 'two', 'three']";
list = list.split(",");
list[0] = list[0].substring(1);
list[list.length - 1] = list[list.length - 1].substring(
0,
list[list.length - 1].length - 1
);
list.forEach((x, i) => {
list[i] = list[i].includes('"') ? list[i].replaceAll('"', "").trim()
: list[i].replaceAll("'", "").trim();
});
console.log(list);