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.key()

The last token in a Firebase database location is considered its key. For example, "fred" is the key for https://samplechat.firebaseio-demo.com/users/fred. Calling key() on any Firebase reference (except the root) will return its key name:

var fredRef = new Firebase("https://samplechat.firebaseio-demo.com/users/fred");
var key = fredRef.key();  // key === "fred"
key = fredRef.child("name/last").key();  // key === "last"

Calling key() on the root of a Firebase reference will return null:

var rootRef = new Firebase("https://samplechat.firebaseio-demo.com");
var key = rootRef.key();  // key === null