I'm trying to iterate through a response from a firebase db and then populate a <select>
with the options that come back. However, when I receive the response from firebase and put it into an array, I cannot iterate through it, as the array length is returned as 0
. Here is my code:
renderChoices() {
var data_list = []
firebase.database().ref("orgs").once("value").then((snapshot) => {
snapshot.forEach(function(childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val().name;
data_list.push(childData);
});
});
console.log(data_list, data_list.length);
}
In the console, I get [] 0
, but when I unpack the array in my devtools, I can see every entry from the db. How can I get this in a format where I can iterate through and render to the page?