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

203
Visualizações
Is there a way to convert a string to a proper array, not an array of strings or an array of characters?

I have this string “[{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}]" and I need to convert into a list [{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}] in JavaScript, is there a way to do that??

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can use the eval() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!)

Please be aware, that eval() shouldnt be used generally as you can read in the article above.

Example:

const array = eval('[{value: 1400, value1: 50, value2: 48}, {value: 1500, value1: 20, value2: 88}]');

Edit: I would suggest to modify you string to fit the JSON-Standard. To achieve this, you would have to put the keys of your objects in quotation marks like this:

let yourString =  '[{"value": 1400, "value1": 50, "value2": 48}, {"value": 1500, "value1": 20, "value2": 88}]';
const array = JSON.parse(`${yourString}`);

This will work ^^

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