Firebase, variable as key name

前端 未结 3 1316
长发绾君心
长发绾君心 2021-01-31 18:14

what I basically want to do is this:

variable = \'whatever\';
fb.set({ variable : \"More Stuff\" });

So this will result in an entry that looks

3条回答
  •  梦如初夏
    2021-01-31 18:17

    For the latest version of Firebase, use brackets around the variable name:

    firebase.database().ref("pathName").set({[variable] : 'MoreStuff'});
    

    Using the other method of setting the index of the variable to the value will create an additional layer in the database structure.

提交回复
热议问题