javascript - Access first datum in Firebase snapshot -


i attempting access attributes of first datum in firebase snapshot consists of 10 urls. no matter try, however, getting whole snapshot. code looks like:

mydataref.limittolast(10).on("child_added", function(snapshot) {  var newimg = snapshot.child("url");   console.log(newimg); }); 

is there way specify [0] or on whole snapshot i'll first datum?

it's tricky sure without seeing data structure, think you're looking for:

mydataref.limittolast(10).on("child_added", function(snapshot) {   var newimg;   snapshot.foreach(function(urlsnapshot) {     if (!newimg) {       newimg = urlsnapshot.val();     }   });   console.log(newimg); }); 

the foreach() loops on child keys of snapshot , invokes inner callback datasnapshot of each of them.

the newimg = urlsnapshot.val(); value of child. may have modify bit based on data structure.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -