Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda