1

I have been working on this for a while now and I cannot seems to find a good/proper way to add objects coming from a DB query to an array holding objects. Please note I am developing a React Native Expo application.

This is basically the code that I have

  var arr = [];

firebase.firestore().collection('Something').where("text", "==" , "text").get().then((querySnapshot) =>{
    querySnapshot.forEach((doc) =>{
      arr += doc.data();
    })
})

The idea here is to have arr populated with the object result of doc.data(). I have looked at a million (if felt like it) tutorials, but I cannot seems to figure out the proper and correct way to populate my array.

Thank you for the help

1 Answer 1

2

If I understood correctly, doc.data() returns objects and you want to populate the array with those objects?

If that is so, try replacing arr += doc.data(); with arr.push(doc.data())

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.