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)
asked Feb 19, 2014 at 13:33
rablentain
6,82513 gold badges55 silver badges104 bronze badges
1 Answer 1
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.
answered Feb 19, 2014 at 13:35
Sign up to request clarification or add additional context in comments.
Comments
lang-js
attachment.sizes[props.size].heightshould work.