I have a list of tuple in string format.
let tuple_list= '[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'
I want it to convert in an array.
("AB", "CD" , "EF", "GH", "IJ", "KL")
Please let me know how can I do that.
I have a list of tuple in string format.
let tuple_list= '[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'
I want it to convert in an array.
("AB", "CD" , "EF", "GH", "IJ", "KL")
Please let me know how can I do that.
let parsed = '[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]';
function parseTuple(t) {
return JSON.parse(t.replace(/\(/g, "").replace(/\)/g, ""));
}
var result = parseTuple(parsed);
console.log(result);
JavaScript does not support tuples so you've to convert it into array so you can do like this
let tuple_list = '[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'
tuple_list = tuple_list.replaceAll("(","").replaceAll(")","")
let result = JSON.parse(tuple_list)
console.log(result)
Andif you want nested array do like this
let tuple_list = JSON.parse('[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'.replaceAll("(", "[").replaceAll(")", "]"))
console.log(tuple_list)
Try this:
JSON.parse('[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'.replaceAll("(", "[").replaceAll(")", "]")).flat()