Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda