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

197
Views
Unable to fetch a key data while iterating through an object

I am iterating through an object. However, it is not catching all the keys. It is catching only a few. It is especially not catching organic_results key. I don't understand why. Kindly help.

 for (var key in this.writeItOutput){ 
    
      if(key == "inline_people_also_search_for"){
      console.log("inline_people_also_search_for")
    }

} 
 
  if(key == 'organic_results'){

    console.log("inside organic_results");
}

  if(key =="related_questions"){
console.log("inside related questions");
 
}


  if(key =="related_searches"){
 console.log("Inside related_searches");
}
      
}

All the keys are:

enter image description here

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

0

you have a bracket that closes your for-in loop just before this line:

if(key == 'organic_results'){

so the steps your script executes are the following:

  1. start for-in loop

  2. set key variable to a key from this.writeItOutput iteration

  3. check whether the key equals to "inline_people_also_search_for"

  4. go to step 2 until all keys in this.writeItOutput are iterated

  5. finish the loop

  6. run if blocks

So when you reach the step 5, your key variable equals ONLY ONE key in this.writeItOutput. What you may want to do is to put all these if blocks inside your for-in loop:

for (var key in this.writeItOutput){ 
   if(key == "inline_people_also_search_for"){
     console.log("inline_people_also_search_for")
   }

// } - this bracket is the problem
 
  if(key == 'organic_results'){
    console.log("inside organic_results");
  }

  if(key =="related_questions"){
    console.log("inside related questions");
  }


  if(key =="related_searches"){
    console.log("Inside related_searches");
  }
      
}
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!