Skip to content

Instantly share code, notes, and snippets.

@anantn
Last active March 4, 2016 00:04
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save anantn/4325052 to your computer and use it in GitHub Desktop.
Save anantn/4325052 to your computer and use it in GitHub Desktop.
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
Copy link

PSekhon commented Dec 21, 2014

,klkj;l

@viscasillas
Copy link

gross

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment