Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

0

It's possible to destructer nested object.

Try something like this:

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!