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

179
Views
Best Method to Grab Specific Keys(Properties) from Nested Object in JavaScript

What is the best method to get specific keys (i.e. "longName") from nested objects with this structure:

const routes = {
   "14094": {
      "routeId": 14094,
      "shortName": "2",
      "longName": "Route 1"
   },
   "14095": {
      "routeId": 14095,
      "shortName": "7",
      "longName": "Route 2"
   },
   "14096": {
      "routeId": 14096,
      "shortName": "42",
      "longName": "Route 3"
   },
   "14097": {
      "routeId": 14097,
      "shortName": "57",
      "longName": "Route 4"
   },

I have tried to console.log(routes[1]), dot notation, and other methods but I am not having any success.

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

0

The structure here is an object of objects. So you can access the longName key-value pair in this manner: routes[14094].longName which should return Route 1, based on the original data.

If you want to get all the longName values for each object, you can use a for loop like this:

for (const key in routes) {
   console.log(routes[key].longName)
   }

You need to first reference the object using the "outer" key (e.g. 14094), then you can use dot notation for the keys in the "inner" object.

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!