I have an array with objects inside. I get the array from my firestore database.
When I get the array, I check if my user has any of the objects. When I check this using includes()
I get false as a return, but the array clearly has the object. What can be the issue?
Check:
const querySnapshot = await getDocs(colRef);
querySnapshot.forEach(async(badge) => {
console.log(userData.obtainedBadges)
if(!userData.obtainedBadges.includes(badge.data())){
console.log(badge.data())
console.log("not includes")
setObtainableBadges(prev => {
return [...prev, badge.data()]
})
} else {
console.log("includes")
setUserBadges(prev => {
return [...prev, badge.data()]
})
}
})
For example one of the objects I check( badge.data()
) :
Object { id: 1, desc: "Play 5 games.", type: "games", reward: 10, condition: 5, img: "/trophies/firsttrophy.png", name: "The First Games" }
querySnapshot
Array:
Array(9) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…} ]
0: Object { img: "/trophies/firsttrophy.png", type: "games", name: "The First Games", … }
1: Object { id: 2, type: "games", name: "The Beginner", … }
2: Object { name: "The Big Brain", id: 50, type: "games", … }
3: Object { condition: 50, id: 4, desc: "Play 50 games.", … }
4: Object { name: "Noob", reward: 10, img: "/trophies/noobmedal.png", … }
5: Object { id: 6, reward: 10, desc: "Reach a minimum high score of 2000.", … }
6: Object { condition: 3000, desc: "Reach a high score of 3000.", name: "Unstoppable", … }
7: Object { desc: "Reach a score of 0 in any gamemode.", id: 9, reward: 25, … }
8: Object { type: "easteregg", condition: "easteregg", desc: "Find an easter egg!", … }
length: 9
<prototype>: Array []
You can see, that my object is the first element in the array. But for some reason, includes()
returns false.