Index
Properties
Methods
Properties
key
ref
Methods
child
-
Gets another
DataSnapshot
for the location at the specified relative path.Passing a relative path to the
child()
method of a DataSnapshot returns anotherDataSnapshot
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"). If the child location has no data, an emptyDataSnapshot
(that is, aDataSnapshot
whose value isnull
) is returned.Parameters
-
path: string
A relative path to the location of child data.
Returns DataSnapshot
-
exists
-
Returns true if this
DataSnapshot
contains any data. It is slightly more efficient than usingsnapshot.val() !== null
.Returns boolean
exportVal
-
Exports the entire contents of the DataSnapshot as a JavaScript object.
The
exportVal()
method is similar toval()
, except priority information is included (if available), making it suitable for backing up your data.Returns any
The DataSnapshot's contents as a JavaScript value (Object, Array, string, number, boolean, or
null
).
forEach
-
Enumerates the top-level children in the
DataSnapshot
.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 ofchild_added
events. That is whereforEach()
comes in handy. It guarantees the children of aDataSnapshot
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).Parameters
-
action: (a: IteratedDataSnapshot) => boolean | void
A function that will be called for each child DataSnapshot. The callback can return true to cancel further enumeration.
-
-
Parameters
Returns boolean | void
-
-
Returns boolean
true if enumeration was canceled due to your callback returning true.
-
getPriority
-
Gets the priority value of the data in this
DataSnapshot
.Applications need not use priority but can order collections by ordinary properties (see Sorting and filtering data).
Returns string | number | null
hasChild
-
Returns true if the specified child path has (non-null) data.
Parameters
-
path: string
A relative path to the location of a potential child.
Returns boolean
true
if data exists at the specified child path; elsefalse
. -
hasChildren
-
Returns whether or not the
DataSnapshot
has any non-null
child properties.You can use
hasChildren()
to determine if aDataSnapshot
has any children. If it does, you can enumerate them usingforEach()
. If it doesn't, then either this snapshot contains a primitive value (which can be retrieved withval()
) or it is empty (in which case,val()
will returnnull
).Returns boolean
true if this snapshot has any children; else false.
numChildren
-
Returns the number of child properties of this
DataSnapshot
.Returns number
toJSON
-
Returns a JSON-serializable representation of this object.
Returns Object | null
val
-
Extracts a JavaScript value from a
DataSnapshot
.Depending on the data in a
DataSnapshot
, theval()
method may return a scalar type (string, number, or boolean), an array, or an object. It may also return null, indicating that theDataSnapshot
is empty (contains no data).Returns any
The DataSnapshot's contents as a JavaScript value (Object, Array, string, number, boolean, or
null
).
The
Reference
for the location that generated thisDataSnapshot
.