1

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?

3
  • 1
    To set an object property you don't use 'var' again. So not: 'var meow.cutekitten = {};' but just 'meow.cutekitten = {};' Commented Sep 11, 2012 at 6:52
  • fixed sorry, that isn't the problem though but thanks ;) Commented Sep 11, 2012 at 6:53
  • also @Aesthete It's not an issue with a specific piece of code this is a general arrays/objects issue. See sq2's answer if it helps you understand what my issue was. Commented Sep 11, 2012 at 6:55

1 Answer 1

3
var propertyName = "cutekitten";
var meow = {};
meow[ propertyName ] = {};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.