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

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

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