Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
undefined inside javascript loop

I want to output a list of all my products that I have in firebase database,for that I go through this loop:

db.collection("products").get().then((querySnapshot) => {

    querySnapshot.forEach((doc) => {
   var wrapper = document.getElementById("wrapper");
   var myHTML = '<h6 id="name">' + doc.name +' </h6>';

    wrapper.innerHTML = myHTML

        console.log(doc.id, " => ", doc.data());
    });
});

However in my html is prints undefined. Can someone point out the problem and how can I solve it? P.S I am new in web

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The name property exists in the DocumentData and not in the DocumentSnapshot itself. Try this:

// no data in original code
// var myHTML = '<h6 id="name">' + doc.name +' </h6>';


var myHTML = '<h6 id="name">' + doc.data().name +' </h6>';
// add data()                       ^^^^
about 4 years ago · Juan Pablo Isaza Report

0

Try This,

db.collection("products").get().then((querySnapshot) => {
    
    let customHtml = ``;
    querySnapshot.forEach((doc) => {
        customHtml += '<h6 id="name">' + doc.name +' </h6>';
    });
    document.getElementById("wrapper").innerHTML = customHtml;
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!