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

177
Views
Get a value from an object inside an object

How do I get the id 43 from country ?

"hq_locations":[{"id":1886112,"address":"10 Rue Laurencin, 69002 Lyon, France","street":"Rue Laurencin","street_number":"10","zip":"69002","lat":45.7527311,"lon":4.8321804,"country":{"id":43,"name":"France","lat":46.227638,"lon":2.213749,"trade_register_office":"Info Greffe"}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reason why it is probably not working is because the hq_locations contains an array that contains an object that contains a child object and some properties.

As you can see the levels you have to bypass before you get to the id of the country is more than just selecting the object in the object and then its property.

An example to access the first element in the row:

const obj = {
    "hq_locations": [{
        "id": 1886112,
        "address": "10 Rue Laurencin, 69002 Lyon, France",
        "street": "Rue Laurencin",
        "street_number": "10",
        "zip": "69002",
        "lat": 45.7527311,
        "lon": 4.8321804,
        "country": {
            "id": 43,
            "name": "France",
            "lat": 46.227638,
            "lon": 2.213749,
            "trade_register_office": "Info Greffe"
        }
    }]
};

console.log(obj.hq_locations[0].country.id)

If you want to access all the elements in the array and select all the ids you'd have to loop it:

   for (let i = 0; i < obj.hq_locations.length; i++) {
    console.log(obj.hq_locations[i].id)
}
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!