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

142
Views
how to split string of arrays depending only on the comas between arrays

I have a string of an array of arrays,and i need to split this string into an array of arrays.

array = "[['<1>', 'likes'], ['<2>', 'reads'], ['<3>', \"doesn't have\"]]"

this what i've tried so far

array.split(",")

This is the wanted result:

[['<1>','likes'], ['<2>', 'reads'],['<3>', \"doesn't have\"]] 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

need to split this string into an array of arrays

As Nick Parsons suggested, change your quotations so they are valid JSON, and use JSON.parse()

const array = `[["<1>", "likes"], ["<2>", "reads"], ["<3>", "doesn't have"]]`
console.log(JSON.parse(array))

If you are unable to reformat the input string, you can replace the single quotes with double quotes with this crazy regex that took me surprisingly long to craft:

const array = "[['<1>', 'likes'], ['<2>', 'reads'], ['<3>', \"doesn't have\"]]"
const arrayJSON = array.replace(/(?<=[\[\]\, ])'|'(?=[\[\]\, ])/g, `"`)
console.log(arrayJSON)
console.log(JSON.parse(arrayJSON))

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!