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.child()

Passing a relative path to the child() method of a DataSnapshot returns another DataSnapshot for the location at the specified relative path. The relative path can either be a simple child name (e.g. fred) or a deeper, slash-separated path (e.g. fred/name/first). If the child location has no data, an empty DataSnapshot (that is, a DataSnapshot whose value is null) is returned.

Assume we have the following data in our Firebase database:

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

We can use child() to inspect a DataSnapshot:

var ref = new Firebase("https://docs-examples.firebaseio.com/samplechat/users/fred");
ref.once("value", function(snapshot) {
  var nameSnapshot = snapshot.child("name");
  var name = nameSnapshot.val();
  // name === { first: "Fred", last: "Flintstone"}

  var firstNameSnapshot = snapshot.child("name/first");
  var firstName = firstNameSnapshot.val();
  // firstName === "Fred"

  var lastNameSnapshot = snapshot.child("name").child("last");
  var lastName = lastNameSnapshot.val();
  // lastName === "Flintstone"

  var ageSnapshot = snapshot.child("age");
  var age = ageSnapshot.val();
  // age === null (because there is no "age" child in the data snapshot)
});