Firebase, variable as key name

前端 未结 3 1350
长发绾君心
长发绾君心 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:33

    Yes. The code is not working as expected because you are using object literal notation, which is the reason the it keeps the variable name as key, because that is how the notation works.

    Solution

    foo = {}; 
    foo[variable] = 'more stuff'; 
    fb.set(foo);
    

提交回复
热议问题