Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda