Home > front end >  FireBase value not printing properly
FireBase value not printing properly

Time:05-01

I need to get all the values of a collection so I did

const q = query(collection(db, "IPAddresses"));
        const querySnapshot = await getDocs(q);
        querySnapshot.forEach((doc) => {
            var newAddress = document.createElement("Label");
            newAddress.innerHTML = JSON.stringify(doc.data());
            AddressDiv.appendChild(newAddress);
        });

The only issue is the values show like this

{"IPAddresses":"Address"}{"IPAddresses":"Address"}{"IPAddresses":"Address"}

I need it like this

"Address" "Address" "Address" 

CodePudding user response:

If you just need a value of a specific field then set that value as innerHTML:

newAddress.innerHTML = doc.data().IPAddresses; // instead of JSON.stringify(doc.data())
  • Related