Matt Coady Matt Coady - 6 months ago 73
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?


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';