1

I have some objects like this: (wordpress attachment object)

attachment.sizes (which is an object and contains:) 
                .full (each contains height and width:)
                     .height
                     .width
                .medium
                       .height
                       .width
                .thumbnail
                          .height
                          .width

And then I have another object:

props.size (which is either "full","medium" or "thumbnail")

Can I in some way write similar to

attachment.sizes.(props.size).height 

To get the height? (That did not work when I tried)

1
  • 1
    I think attachment.sizes[props.size].height should work. Commented Feb 19, 2014 at 13:34

1 Answer 1

4

Yes, using []:

attachment.sizes[props.size].height 

Both notations, a.b and a['b'], are equivalent, but only [] let you use a variable name as the property.

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.