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

126
Vistas
How to access a specific property within a nested but fixed structure of arrays and objects

This is my array

let result=[
  { lon: -122.08, lat: 37.39 },
  [ { id: 800, main: 'Clear', description: 'clear sky', icon: '01d' } ],
  'stations',
  {
    temp: 282.55,
    feels_like: 281.86,
    temp_min: 280.37,
    temp_max: 284.26,
    pressure: 1023,
    humidity: 100
  },
  16093,
  { speed: 1.5, deg: 350 },
  { all: 1 },
  1560350645,
  {
    type: 1,
    id: 5122,
    message: 0.0139,
    country: 'US',
    sunrise: 1560343627,
    sunset: 1560396563
  },
  -25200,
  420006353,
  'Mountain View',
  200
]

I want to fetch icon property, so I tried this

for (let i in result) {
    if (i == 1) {
        console.log(result[i]['icon']);
    }
}

But I got "undefined" as an output. please help me access the icon property in this array.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is not recommended to use for..in with arrays. As result is an array, then you can use index to fetch the icon property as:

result[1][0].icon

let result = [
  { lon: -122.08, lat: 37.39 },
  [{ id: 800, main: "Clear", description: "clear sky", icon: "01d" }],
  "stations",
  {
    temp: 282.55,
    feels_like: 281.86,
    temp_min: 280.37,
    temp_max: 284.26,
    pressure: 1023,
    humidity: 100,
  },
  16093,
  { speed: 1.5, deg: 350 },
  { all: 1 },
  1560350645,
  {
    type: 1,
    id: 5122,
    message: 0.0139,
    country: "US",
    sunrise: 1560343627,
    sunset: 1560396563,
  },
  -25200,
  420006353,
  "Mountain View",
  200,
];

const res = result[1][0].icon;

console.log(res);

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