I have to take each data of the array inside an array but it doesn't work when I use something like tmp.name
or tmp[0].name
would result undefined
and even tmp.length
result 0
var tmp = [];
var db = firebase.firestore();
var docCollection = db.collection('doctors');
var assignedDoctors = docCollection.where('assign', '==', user.key).get();
assignedDoctors.then(function(doc){
let i = 0;
doc.forEach(function(md){
tmp.push(md.data());
tmp[i].key = md.id;
i++;
});
}).catch(function(e){
console.log(e);
});
console.log(tmp)
the tmp result
[]
0: {assign: "userA", name: "NameA"}
1: {assign: "userA", name: "NameB"}
length: 2
__proto_: Array(0)