Set a priority for the data at this database location.
A priority can be either a number or a string and is used to provide
a custom ordering for the children at a location (if no priorities are
specified, the children are ordered by name). This ordering affects the
enumeration order of DataSnapshot.forEach() as well as the prevChildName
parameter passed to
You cannot set a priority on an empty location. For this reason,
setWithPriority() should be used when setting initial data with a
specific priority, and
setPriority() should be used when updating the
priority of existing data.
Children are sorted based on this priority using the following rules:
- Children with no priority come first.
- Children with a number as their priority come next. They are sorted numerically by priority (small to large).
- Children with a string as their priority come last. They are sorted lexicographically by priority.
- Whenever two children have the same priority (including no priority), they are sorted by name. Numeric names come first (sorted numerically), followed by the remaining names (sorted lexicographically).
Note that number priorities are stored and ordered as IEEE 754 double-precision floating-point numbers. Names are always stored as strings and are treated as numeric only when they can be parsed as a 32-bit integer.
Setting the priority to
null removes any existing priority.
var fredRef = new Firebase('https://docs-examples.firebaseio.com/samplechat/users/fred'); fredRef.setPriority(1000); // We have changed the priority of fred's user data to 1000