Interface representing a Firebase Realtime Database data snapshot.




  • new DataSnapshot(data: any, path?: string, app?:, instance?: string): DataSnapshot
  • Parameters

    • data: any
    • Optional path: string
    • Optional app:
    • Optional instance: string

    Returns DataSnapshot


Private Optional app



instance: string



  • get key(): string
  • The key (last part of the path) of the location of this DataSnapshot.

    The last token in a Database location is considered its key. For example, "ada" is the key for the /users/ada/ node. Accessing the key on any DataSnapshot will return the key for the location that generated it. However, accessing the key on the root URL of a Database will return null.

    Returns string


  • get ref(): firebase.database.Reference
  • Returns a Reference to the Database location where the triggering write occurred. Has full read and write access.

    Returns firebase.database.Reference



  • Gets a DataSnapshot for the location at the specified relative path.

    The relative path can either be a simple child name (for example, "ada") or a deeper slash-separated path (for example, "ada/name/first").


    • childPath: string

    Returns DataSnapshot

    The specified child location.


  • exists(): boolean
  • Returns true if this DataSnapshot contains any data. It is slightly more efficient than using snapshot.val() !== null.

    Returns boolean

    true if this DataSnapshot contains any data; otherwise, false.


  • exportVal(): any
  • Exports the entire contents of the DataSnapshot as a JavaScript object.

    The exportVal() method is similar to val(), except priority information is included (if available), making it suitable for backing up your data.

    Returns any

    The contents of the DataSnapshot as a JavaScript value (Object, Array, string, number, boolean, or null).


  • forEach(action: (a: DataSnapshot) => boolean | void): boolean
  • Enumerates the DataSnapshots of the children items.

    Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by val() is not guaranteed to match the ordering on the server nor the ordering of child_added events. That is where forEach() comes in handy. It guarantees the children of a DataSnapshot will be iterated in their query order.

    If no explicit orderBy*() method is used, results are returned ordered by key (unless priorities are used, in which case, results are returned by priority).


    • action: (a: DataSnapshot) => boolean | void

      A function that will be called for each child DataSnapshot. The callback can return true to cancel further enumeration.

    Returns boolean

    true if enumeration was canceled due to your callback returning true.


  • getPriority(): string | number | null
  • Gets the priority value of the data in this DataSnapshot.

    As an alternative to using priority, applications can order collections by ordinary properties. See Sorting and filtering data.

    Returns string | number | null

    The priority value of the data.


  • hasChild(childPath: string): boolean
  • Returns true if the specified child path has (non-null) data.


    • childPath: string

    Returns boolean

    true if data exists at the specified child path; otherwise, false.


  • hasChildren(): boolean
  • Returns whether or not the DataSnapshot has any non-null child properties.

    You can use hasChildren() to determine if a DataSnapshot has any children. If it does, you can enumerate them using forEach(). If it doesn't, then either this snapshot contains a primitive value (which can be retrieved with val()) or it is empty (in which case, val() will return null).

    Returns boolean

    true if this snapshot has any children; else false.


  • numChildren(): number
  • Returns the number of child properties of this DataSnapshot.

    Returns number

    Number of child properties of this DataSnapshot.


  • toJSON(): Object
  • Returns a JSON-serializable representation of this object.

    Returns Object

    A JSON-serializable representation of this object.


  • val(): any
  • Extracts a JavaScript value from a DataSnapshot.

    Depending on the data in a DataSnapshot, the val() method may return a scalar type (string, number, or boolean), an array, or an object. It may also return null, indicating that the DataSnapshot is empty (contains no data).

    Returns any

    The DataSnapshot's contents as a JavaScript value (Object, Array, string, number, boolean, or null).