I'm running into a weird issue where once I push a value to a Firebase object, two things happen:
- I can't access it in the array I receive when I pull the object from Firebase.
- The array I receive has no
lengthproperty.
Here is what my Firebase structure looks like:
"user_solutions": { "0": { "user_id": 0, "clue_id": 0, "hunt_id": 0, "completed": 1 }, "1": { "user_id": 0, "clue_id": 1, "hunt_id": 0, "completed": 0 }, "2": { "user_id": 0, "clue_id": 1, "hunt_id": 1, "completed": 0 } }, "-KHxBMZwVMzyiMIcbMdr": { clue_id: 1, completed: 0, hunt_id: 0, user_id: 0 } Here is the problematic function:
userSolutionsRef.orderByChild('user_id').startAt(0).endAt(0).once('value', (snap) => { var solution = snap.val(); for (var i = 0; i < solution.length; i++) { if (solution[i].hunt_id == 0) { solutionsForThisHunt.push(solution[i]); } } this.populateArray(solutionsForThisHunt); }); When I run the debugger, solution has the value Object {0: Object, 1: Object, 2: Object, -KHxBMZwVMzyiMIcbMdr: Object}, but the length property is undefined. solutionsForThisHunt never gets populated. Also, I can access the objects individually in the debugger via snap.val()[0]/snap.val()[1]/snap.val()[2], but for some reason when I try accessing snap.val()[3] it is undefined, although it should be populated.
snap.valreturn a real array or another iterable? What doesArray.isArrayreturn? (developer.mozilla.org/de/docs/Web/JavaScript/Reference/…)