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

236
Visualizações
React Native: Else in a for loop is not working, the loop skips the first condition and defaults to using the else in the loop

In the code below I have a for loop which goes through a json array, and then pushes data to a new array to be used. The problem is that the loop seems to be using the else and completely skipping the first condition no matter what. This is odd behavior, and I dont know where the error/bug is.

const findCompaniesByCategory = async (category) => {
  setCat(category)
var zip = await AsyncStorage.getItem('locationZip')
var newCompanies = []
for(var i in companies){
  if(companies[i].category == category && companies[i].zip == zip){
    
    await newCompanies.push(companies[i])
    await setSuggestions(false)
    await  setUsers(newCompanies)
    await setHide(false)
    setNoResults(false)
    await setCompaniesView(true) 
  }else if(companies[i].category != category){
    await setHide(false)
    setCompaniesView(false)
    setNoResults(true)
  }
}
}
about 4 years ago · Santiago Gelvez
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