Jump to top

DataSnapshot

interface

A DataSnapshot contains data from a Database location.

Any time you read data from the Database, you receive the data as a DataSnapshot. A DataSnapshot is passed to the event callbacks you attach with on() or once(). You can extract the contents of the snapshot as a JavaScript object by calling the val() method. Alternatively, you can traverse into the snapshot by calling child() to return child snapshots (which you could then call val() on).

Properties

key

</>

The key (last part of the path) of the location of this DataSnapshot.

key: string | null;

ref

</>

The Reference for the location that generated this DataSnapshot.

ref: Reference;

Methods

child

</>

Gets another DataSnapshot for the location at the specified relative path.

child(path: string): DataSnapshot;

exists

</>

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

exists(): boolean;

exportVal

</>

Exports the entire contents of the DataSnapshot as a JavaScript object.

exportVal(): any;

forEach

</>

Enumerates the top-level children in the DataSnapshot.

forEach(action: Function): boolean;

getPriority

</>

Gets the priority value of the data in this DataSnapshot.

getPriority(): string | number | null;

hasChild

</>

Returns true if the specified child path has (non-null) data.

hasChild(path: string): boolean;

hasChildren

</>

Returns whether or not the DataSnapshot has any non-null child properties.

hasChildren(): boolean;

numChildren

</>

Returns the number of child properties of this DataSnapshot.

numChildren(): number;

toJSON

</>

Returns a JSON-serializable representation of this object.

toJSON(): object | null;

val

</>

Extracts a JavaScript value from a DataSnapshot.

val(): any;