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

123
Views
Get the id of an object in a json request?

So I have to get the first object of this list:

{
"2489": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
},

"2490": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
}

}

I don't know beforehand the IDs ['2489'] and ['2490']. Sometimes it responses only one of these IDs, sometimes 3 or more.

How can I get like ['2490'].status.idstatus without knowing ['2490']?

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

0

There are several ways to do this. If you're running a modern JS environment, you can use Object.keys or Object.values.

Assuming your JSON response object is a variable named res, you can construct a dynamic array of IDs like this:

const ids = Object.keys(res) // ["2489", "2490", ...]

If you don't care about the IDs at all and want an array of all the inner objects, try this:

const items = Object.values(res) // [ { "status" : ... }, ... ]
about 4 years ago · Juan Pablo Isaza Report

0

you can do it using Object.values and map or if you need the key you can use Object.entries

const data = {
"2489": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
},

"2490": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
}
}

const statusIds = Object.values(data).map(d => d.status.idstatus)
console.log(statusIds)

const statusIdAndKey = Object.entries(data).map(([k, d]) => [k, d.status.idstatus])
console.log(statusIdAndKey)

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!