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