How can I access a JavaScript object which has spaces in the object's key?
Use ECMAscripts "bracket notation":
myTextOptions[ 'character names' ].kid;
You can use that notation either way, reading & writting.
For more information read out here:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
Properties of JavaScript objects can also be accessed or set using a bracket notation (for more details see property accessors). Objects are sometimes called associative arrays since each property is associated with a string value that can be used to access it. So, for example, you could access the properties of the myCar object as follows:
myCar['make'] = 'Ford';
myCar['model'] = 'Mustang';
myCar['year'] = 1969;
For more, read on at Working with JS Objects.
So in your case it's myTextOptions['character names'].kid;
We can also do this by -
myTextOptions[ 'character names' ]['kid']
;
This is useful when we have consecutive keys which consist of space.