For some reason I am having the hardest time get to values of an object stored within an array. Here is how I am populating my array:
var arrActivities = [];
//other not needed variables here..
function logIt(){
firebase.firestore().collection('PostedFunActivities').where("geolocation", ">=", range.lower).where("geolocation", "<=", range.upper).get().then((querySnapshot) =>{
querySnapshot.forEach((doc) =>{
arrActivities.push(doc.data());
})
});
console.log(arrActivities);
console.log(arrActivities.length);
}
The result of my console.log
is the following:
[] 0: {location: "Mānana Ridge Trail, Pearl City, HI, USA", geolocation: "87z9yj0x5"} 1: {timePosted: "13:50:05 GMT-1000 (HST)", geolocation: "87zc52x78"} 2: {userId: "QevGxIV57lZuC92oTjp80N9WcIy2", title: "Koko crater arch"} 3: {timePosted: "13:46:55 GMT-1000 (HST)", image: "0.1565895502212029"} 4: {title: "Bike", datePosted: "Fri Jun 12 2020"} length: 5 __proto__: Array(0)
I feel like i tried a million way to get either the length of the array or the values within, but I cannot get to any of that.
Some of my attempts involve suggestions coming from these SO posts (these attempts are to get the lenght):
data.length
Object.keys(data).length
I would really appreciate any suggestions on how to get the length and values of my objects.
*My Objective
I need to get the length of the array which in this case would be 5. Also I need to be able to get into my values for example the the userId
within the 3rd element in the array.