Dashes in Javascript Objects

Super quick note on something that has been bugging me lately.  If you’re using dot notation to access Javascript properties, you can’t have a property name with dashes in it (e.g. image.attributes.media_details.sizes.plugin-name-headshot ). Instead you need to use bracket notation with quotation marks. So in replace the example above with image.attributes.media_details.sizes['plugin-name-headshot'].

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.