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

138
Vistas
How to destructure my api data in reactjs?

I am trying to destructure my array of objects with .map ? I have tried a few things but keep getting stuck. I am able to access single data by using the index but struggling with how to do it for them all.

I know it's something like this

const {name} = product;
and
const {attributes:name} = product;
but they don't work, they print "undefined".

Also tried this -

console.log(product.map(({name}) => (console.log(name))))

This is the data 

    console.log(product);
    
    
    {
        "attributes": {
            "image": {
                "data": []
            },
            "name": "test",
            "description": "test product",
            "price": 20,
            "quantity": 0
        }
    }

This is what I want to achieve

<div className='grid grid-cols-4'>
        {product.map(({attributes: name})=> (
          <p>{name}</p>
        ))}
      </div>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's possible to destructer nested object.

Try something like this:

product.map(({attributes:{name}})=> ...
about 4 years ago · Juan Pablo Isaza Denunciar

0

  • since it's Object this will work
const { name } = product.attributes;

or

<p>{product.attributes.name}</p>
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