If I want to get the key of a pushed item I found I can do something like this:
someRef.push(newItem).then(function(result) {
var key = result.path.o[1]
// do something with key
})
Will the path.o property possibly change in future versions? Is there a better way to get the key of a newly pushed item that I'm missing?
You should use the return value of the push() call instead:
var ref = someRef.push(newItem);
var key = ref.key;
// do something with key
The path.o property is not an actual API and it just caused by minification and will certainly break in future versions. Nicely, the code above works synchronously and you don't actually have to wait for the push to finish before getting the key of the new ref.
Most helpful comment
You should use the return value of the
push()call instead:The
path.oproperty is not an actual API and it just caused by minification and will certainly break in future versions. Nicely, the code above works synchronously and you don't actually have to wait for the push to finish before getting the key of the new ref.