How to access a string “key” in Vue that includes hyphens, spaces or other special characters

holly bourneville
2 min readJul 11, 2023
Photo by Christin Hume on Unsplash

Usually in Vue, you would use the dot . notation to access a normal key, but when you have a key that has spaces or special characters you need to use the square bracket notation [] instead as the dot notation expects a valid JavaScript identifier as the key, and spaces and special characters are not allowed in identifiers.

--

--

holly bourneville

Hi Im Holly! I’m from New Zealand. I’m in my first job as a Front End Web Developer and want to share my learnings and thoughts along the way!