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

197
Views
Iterate through JSON File in Javascript

I want to work with an JSON File in Javascript I got from my Flask server via a Axios Get-Request.

Its build like this:

{
  "data": [
    {
      "item": "[224,4,1,80,207,137,153,132]", 
      "name": "A1"
    }, 
    {
      "item": "[224,4,1,80,207,137,153,136]", 
      "name": "A2"
    }, 
    {
      "item": "[224,4,1,80,207,137,157,190]", 
      "name": "A3"
    }
  ]
}

I make my request with this and I can see the output in the terminal:

getInitialBoxesA() {
      const path = 'http://localhost:5000/getAllBoxesA';
      axios.get(path)
        .then((res) => {
          console.log(res.data);
        })
        .catch((error) => {
          // eslint-disable-next-line
          console.error(error);
        });
    },

How can i iterate through this Array in Javascript?

I tried res.data[0] or res.data[0].item

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

0

Axios returns the actual response body in res.data. Given your JSON, you would need to iterate on res.data.data.

axios.get(path)
  .then((res) => {
    if (res.status === 200 && res.data?.data.length) {
      for (obj of res.data.data) {
        console.log(obj)
      }
    }
  })
  .catch((error) => {
    // eslint-disable-next-line
    console.error(error);
  });
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!