Michael Zaporozhets
Michael Zaporozhets

Reputation: 24526

Trouble with Objects

Basically i'm having trouble with something that i'm sure is super duper simple but I just don't know what to call it and therefore I am having trouble searching for an answer. :(

Basically, say I've declared an object, i.e var meow = {}; and then i decide to create an object within that by doing something like meow.cutekitten = {}; this is all straight forward and i end up with an object called cutekitten within that.

My issue is, what if I've declared cutekitten as a variable and i want to use the contents of that variable as the name of this new object rather than the variable name?

Upvotes: 1

Views: 32

Answers (1)

sq2
sq2

Reputation: 595

var propertyName = "cutekitten";
var meow = {};
meow[ propertyName ] = {};

Upvotes: 3

Related Questions