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

134
Visualizações
Need to put this object into an array, how?

I need convert following in the EXACT format shown below with javascript, could you please suggest how to achieve this

from: {"healthy":true,"unhealthy_reasons":[]}
to: [{"healthy":true,"unhealthy_reasons":[]}]

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

0

If that's all you need to do, you can just wrap array brackets around the variable that contains the object:

let initialObject = {"healthy":true,"unhealthy_reasons":[]};
let arrayedObject = [initialObject];

But I'm wondering if there's more to this. If this is actually part of a more complicated task, just add that to your question and you'll get a more complete answer.

about 4 years ago · Juan Pablo Isaza Relatório

0

Use JSON.parse() and JSON.stringify()

let data = '{"healthy":true,"unhealthy_reasons":[]}';
let parsed = JSON.parse(data);
//TO get an array
console.log([parsed])
//TO get a string
console.log(JSON.stringify([parsed]))

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