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


Generate a new child location using a unique name and returns a Firebase reference to it. This is useful when the children of a database location represent a collection of items. See Saving Lists of Data.

You can optionally pass a value to push() and the value will be immediately written to the generated location. If you don't pass a value to push(), nothing is written and the child will remain empty unless written to using set().

The unique name generated by push() is prefixed with a client-generated timestamp so that the resulting list will be chronologically-sorted.

var messageListRef = new Firebase('');
var newMessageRef = messageListRef.push();
    newMessageRef.set({ 'user_id': 'fred', 'text': 'Yabba Dabba Doo!' });
// We've appended a new message to the message_list location.
var path = newMessageRef.toString();
// path will be something like
// ''
var messageListRef = new Firebase('');
    messageListRef.push({ 'user_id': 'fred', 'text': 'Yabba Dabba Doo!' });
// Same effect as the previous example, but we've combined the push() and the set().