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

103
Visualizações
Parse a string with a key and value to an object

[Edited because my question was not clear]

I would like to parse each string from an array into an object as its key with an assigned value e.x.:

There is an array called dates.

This is dates[0]

"2022-02-01"

And I would like to parse it in an object that looks like this:

let datesObj = { "2022-02-01": {selected: true, marked: true} }

I have looked into JSON.parse() but I have not been able to apply it to my needs in this case (if that is even the solution).

I haven't been able to find a suitable solution, so a big thank you to anyone willing to help.

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

0

wrap your string with breakets

var mystring='{"2022-02-01": {selected: true, marked: true}}'; 

and then try parsing it with

var myobj=JSON.parse(mystring);
about 4 years ago · Juan Pablo Isaza Relatório

0

Like this?

function parse(date)
{
    const res = {}
    res[date] = {
        selected: true, 
        marked: true
    }
    return res;
}
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