Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Firebase: Get the first item in a list. This snippet retrieves only the first item in a list.
function makeList(ref) {
var fruits = ["banana", "apple", "grape", "orange"];
for (var i = 0; i < fruits.length; i++) {
ref.push(fruits[i]);
}
}
function getFirstFromList(ref, cb) {
ref.startAt().limit(1).once("child_added", function(snapshot) {
cb(snapshot.val());
});
}
// Running this should popup an alert with "banana".
function go() {
var testRef = new Firebase("https://example.firebaseIO-demo.com/");
makeList(testRef);
getFirstFromList(testRef, function(val) {
alert(val);
});
}
@PSekhon

This comment has been minimized.

Copy link

commented Dec 21, 2014

,klkj;l

@viscasillas

This comment has been minimized.

Copy link

commented Oct 2, 2015

gross

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.