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

173
Views
How do i get the values of object in arrays react js

Object { rows: (1) […], count: 3 } ​ My api is giving me this

count: 3 ​rows: Array [ {…} ] ​​0: Object { ELIGIBILITATE: "2022-04-10", BFA: "2022-04-11", id: "c53d945e-4bb1-49ab-91ca-c9e046ac5de7", … } ​​​Name:"Paul" ​​​BFA: "2022-04-11"

how to display the values in react? i've tried the following with no luck

   class Test extends React.Component{
constructor()
{
    super()
    this.state={
        row:[            
        ]
    }
}

componentDidMount()
{
    const axios = require('axios');

    // Make a request for a user with a given ID
    axios.get('myapi')
      .then( response =>{
        // handle success
        console.log(response);
        this.setState({row:response.data});
      })
      .catch(function (error) {
        // handle error
      console.log(error);
      })
      .then(function () {
        // always executed
      
      });
    
}

render() {

    const { row } = this.state;


    return (

      <div>

        <div>

          {Object.keys(row).map(([key, value]) => {
 console.log(row);
            return (

              <div>

                {key} = {value.Nume}

              </div>

            );

          })}

        </div>

      </div>

    );

}

} export default Test

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

TLDR:

That's because the value you're setting for state.row is an array.

Try this: this.setState({row:response.data.rows[0]});

Explanation

The response from your request - response.data - is an object with the following keys: count and rows.

count is self explanatory.

rows on the otherhand is returned as an array of objects, which is what you're setting the value of state.row to.

Since you're expecting an object and not an array of objects (An assumption from your render code), you'll need to extract it from the response as so response.data.rows[0]

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!