javascript - How to loop through the data I receive from snapshot.val() and push it to an array based on keys -


i want loop through data receive snapshot.val() based on user keys , push them array. tried doing of for..in loop this,

firebase.database().ref('\interests').child("i dine with").on('value', (snapshot) => {   var data = snapshot.val();   if(snapshot.exists()){     for(let key in data){       console.log("data[key]",data[key]);       this.intval.push(data[key]);       console.log("intval",this.intval);     }   } }) 

but i'm getting this,

enter image description here

if notice, first array contains 1 object under user key , second array contains 3 objects under user keys. how can push every single value in separate array?

any appreciated! thanks

there datasnapshot.foreach() method precisely purpose:

firebase.database().ref('\interests').child("i dine with").on('value', (snapshot) => {   snapshot.foreach((child) => {     console.log(child.key, child.val());      this.intval.push(child.val());     console.log("intval",this.intval);   });   } }) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -