Home > Mobile >  How do I fetch the value from a key in firebase using javascript
How do I fetch the value from a key in firebase using javascript

Time:04-02

See the image i want to fetch this value in javascript

 var dbImages = firebase.database().ref("images");

 dbImages.on("value", function(images){

    if(images.exists()){
        var imageshtml = ""; 
        images.forEach(function(fetchImages){

             console.log("key: "   fetchImages.key);
             console.log("title: "   fetchImages.title);
             console.log("url: "   fetchImages.url);

        });
     }

});

Its only showing key value not other value i want to view key value and also the value of key value please help guys

This is the output of my javascript

CodePudding user response:

You are using forEach() and DataSnapshot of /orders node where each child node seems to be a category and not the image itself. You'll have to loop over each image of the categories to list them:

firebase.database().ref("images").once("value").then((imagesCategories) => {
  if (imagesCategories.exists()) {
    var imageshtml = "";

    // For each category
    imagesCategories.forEach(function(categoryImages) {
      // For each category image
      categoryImages.forEach(function(image) {
        // Append data to imageshtml from here
        console.log(image.val().url)
        console.log(image.val().title)
      })
    })
  }
});
  • Related