how to deal with firebase onsnapshot as an object or array?

  arrays, firebase, javascript, object

im doing orders onsnapshot from firebase but im confused how to deal with it, I get an [] when I log it out but when I logout the type of orders it says object,

I’m trying to add the id of each order and place it inside the array orders along with the existing data but its not working , if I

console.log(orders[0]) I get undefined and if I treat it as an object orders['0'] i also get undefined.

here is the code:
im using vuejs mounted

async mounted() {
let id = [];
let orders = [];
await db.collection("orders").onSnapshot(doc => {
  doc.docs.forEach(x => {
    id.push(x.id);
    orders.push(x.data());
  });
});


for (order in orders) {
  let i = 0;
  order.id = id[i];
  i++
}
console.log(orders);

}}

the result of this code is the same orders array without any change at all.

Source: Ask Javascript Questions

LEAVE A COMMENT