Matt Coady Matt Coady - 1 year ago 132
Javascript Question

Firebase, variable as key name

what I basically want to do is this:

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

So this will result in an entry that looks like:

whatever: "More Stuff"

Currently it just ends up as

variable: "More Stuff"

Can this be done?

Answer Source

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.


foo = {}; 
foo[variable] = 'more stuff'; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download