How can i access an array key with a space?
Standard way,
{{MyArray.name}}
Key with space,
{{MyArray.first name}} or {{MyArray['first name']}}
doesn't work.
Use bracket notation to access a key that contains a space in an object, e.g. obj['my key'] . The bracket [] notation syntax allows us to access an object's key, even if it contains spaces, hyphens or special characters.
Whitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON. It can also be minified with no affect to the data.
Object Keys Are Strings. Object keys with underscores and camelCase (no spaces) don't require the bracket syntax, but object keys with spaces and hyphens do. You may prefer the code readability of the . dot syntax, in which case you'll want to avoid spaces in your object keys: you might write object.
JavaScript object property names can be any string, including having spaces in the name. However, object property names that are not valid JavaScript identifiers, can only be: Specified using quotes, and; Accessed using the bracket property accessor notation.
Use brackets in conjunction with dots, without quotes:
{{MyArray.[first name]}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With