When querying a firebase database and pushing the results into an array to remove duplicates, everything appears to be working fine. However, I am encountering an issue where the length of the final array is 0 even though there is data present.
let interests = [
'-KpUpVi7-2W_JmR16HuC',
'-KpUpYwC_FRulbXZnULK',
'-Kpd3J9gNECwWSG6xAvt',
'-KpUpbP3AGKs28McNrBh'
]
let finalArray = [];
interests.forEach((interest) => {
this.hangoutsService.getInterestUsers(interest)
.subscribe(
(res) => {
//console.log('the results: ', res)
res.forEach((uid) => {
//console.log(uid)
finalArray.push(uid)
})
}
)
})
console.log('final array: ',finalArray)
console.log('final array length: ',finalArray.length)
This is the method being called:
getInterestUsers(interest){
return this.db.object(`usersPerInterest/${interest}`)
.map((r) => {
return Object.keys(r)
})
}
A screenshot of the console can be viewed here.
I'm unsure what I might be missing here. Any insights?