How to access a JavaScript object which has spaces in the object’s key?

Sometimes, we want to access a JavaScript object which has spaces in the object’s key.

In this article, we’ll look at how to access a JavaScript object which has spaces in the object’s key.

How to access a JavaScript object which has spaces in the object’s key?

To access a JavaScript object which has spaces in the object’s key, we use square brackets.

For instance, we write

myTextOptions["character names"].kid;

to get the "character names" property from myTextOptions.

Then we get the kid property from the returned object.

Conclusion

To access a JavaScript object which has spaces in the object’s key, we use square brackets.