Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda