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

195
Views
can I pick a grandchild value directly in object without being through parent value?

I need to pick up value from a returned API object, the hierarchy is like this

{"name":
       {"common":"Germany",
        "official":"Federal Republic of Germany",
        "nativeName":
             {"deu":
                {"official":"Bundesrepublik Deutschland",
                 "common":"Deutschland"}}},
  "currencies":
        {"EUR":
             {"name":"Euro",
              "symbol":"€"}}

I want to pick up "Deutschland", so I write like name.nativeName.deu.common , but the problem is by each different user input, the country name changes each time, and "deu" and "EUR" also will be different, in this example, is that a way that I can pick up the value "common" under "nativeName" and "name" under "currencies", without going through their parents "deu" and "EUR"?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

It looks like the API may return a response with multiple keys on both nativeName and currencies, so here's an example that returns all values as array.

const apiResponse = {
  "name": {
    "common": "Germany",
    "official": "Federal Republic of Germany",
    "nativeName": {
      "deu": {
        "official": "Bundesrepublik Deutschland",
        "common": "Deutschland"
      }
    }
  },
  "currencies": {
    "EUR": {
      "name": "Euro",
      "symbol": "€"
    }
  }
}

const nativeNames = Object.keys(apiResponse.name.nativeName).map(key => {
  return apiResponse.name.nativeName[key].common;
});

const currencies = Object.keys(apiResponse.currencies).map(key => {
  return apiResponse.currencies[key].name;
});

console.log(nativeNames);
console.log(currencies);

about 4 years ago · Santiago Gelvez 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!