You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog

DataSnapshot.exists()

Assume we have the following data in our Firebase database:

{
  "name": {
    "first": "Fred",
    "last": "Flintstone"
  }
}

We can test for the existence of certain keys within a DataSnapshot using its exists() method:

var ref = new Firebase("https://docs-examples.firebaseio.com/samplechat/users/fred");
ref.once("value", function(snapshot) {
  var a = snapshot.exists();
  // a === true

  var b = snapshot.child("name").exists();
  // b === true

  var c = snapshot.child("name/first").exists();
  // c === true

  var d = snapshot.child("name/middle").exists();
  // d === false (because there is no "name/middle" child in the data snapshot)
});