As a newcomer to the world of Firebase and JavaScript, I am facing challenges in accessing data from an array of complex objects.
Specifically, I need to retrieve the Date '02-01-2018' from each record. While I can retrieve the key, I am unsure how to access this particular date. I have shared screenshots of my database and the returned values for reference:
https://i.sstatic.net/h6wm8.png
https://i.sstatic.net/fsihK.png
{
"dailyPrices": {
"01-50005": {
"04-01-2018": {
"brands": "",
"editorID": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086269666d6d6e486269666d6d6e266b6765">[email protected]</a>",
"name": "dddf",
"phone": "",
"place": "errr"
},
// more data follows in a similar format
}
}
}
<input type="text" name="ordDetailTXT" id="ordDetailTXT" value="dailyPrice">
Code
function findOrderDetails(parentKey)
{
var returnArr = [];
var fetchRecord = database.ref(parentKey);
fetchRecord.on('value', function(snapshot) {
var item = snapshot.val();
item.key = snapshot.key;
returnArr.push(item);
});
}
function btnClickedOrdDetails(){
var parentkey = ("#ordDetailTXT").val();
findOrderDetails(parentKey);
}