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

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