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

122
Views
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 answers
Answer question

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 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!