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

Firebase.setPriority()

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 child_added and child_moved events.

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:

  1. Children with no priority come first.
  2. Children with a number as their priority come next. They are sorted numerically by priority (small to large).
  3. Children with a string as their priority come last. They are sorted lexicographically by priority.
  4. 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