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

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

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 Denunciar

0

Like this?

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