Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How to convert a list of tuple that is a string into an Array in Javascript

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.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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);
about 4 years ago · Juan Pablo Isaza Report

0

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)

about 4 years ago · Juan Pablo Isaza Report

0

Try this:

JSON.parse('[("AB", "CD"), ("EF", "GH"), ("IJ", "KL")]'.replaceAll("(", "[").replaceAll(")", "]")).flat()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!