Gotcha- Firebase won't save empty arrays

22 Sep 2017

If you try to write an empty array ([]) to Firebase, it instead stores nothing. When it makes its way back to your frontend (via VueFire in my case) it's undefined.

You can verify this by looking at the Firebase console - eg https://console.firebase.google.com/project/myproject/database/data and seeing that the whole key is missing.

This can break your code if you're expecting an array, eg a vue component that does:

data: function() { 
    return {
        name: this.contact.name,
        tags: this.contact.tag_list
    }
},

To recover, reconstitute the empty array on the client side:

data: function() { 
    return {
        name: this.contact.name,
        tags: this.contact.tag_list || []
    }
},