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
Post a Comment