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

136
Visualizações
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 Respostas
Responde à pergunta

0

It's possible to destructer nested object.

Try something like this:

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

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 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