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

143
Vistas
Generate objects with dynamic "key" using spread operators

I want to generate an object where the key is the value of the index from the mapped data as shown in the code below

{data.map(({ quest, answers }, index) => {
                  <Radio.Group
                    name={index}
                    defaultValue={def}
                    onChange={(value) => {
                    setVal({...(val), index: JSON.stringify(value)}  )
                      
                    }}
                  >
                    {answers.map((ans, key) => {
                      return (
                        <Radio value={key + 1}>
                          {ans}
                        </Radio>
                      );
                    })}
                  </Radio.Group>
})}

So "index" in this line

setVal({...(val), index: JSON.stringify(value)} )

should be from this line

{data.map(({ quest, answers }, index) => {

The problem is the code above returns the index value as the string "index" instead of the value of index from the mapped data i am working with

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use it like this:-

setVal({...(val), [index]: JSON.stringify(value)} )

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