0

So I have fetch and it returns this:

{
    Global Quote: {
        01. symbol: "TSLA",
        02. open: 595.0000,
        03. high: 607.570,
        04. low: 502.0000,
        05. price: 546.6200,
        06. volume: 22460363,
        07. latest trading day: 2020-03-13,
        08. previous close: 560.5500,
        09. change: -13.9300,
        10. change percent: -2.4851%
    }
}

How do I work with it, when it has multiple words in property name ?

Michal Gally
  • 127
  • 1
  • 9
  • 1
    `object["Global Quote"]` – Pointy Mar 14 '20 at 17:59
  • 1
    Does this answer your question? [How can I access a JavaScript object which has spaces in the object's key?](https://stackoverflow.com/questions/8317982/how-can-i-access-a-javascript-object-which-has-spaces-in-the-objects-key) – Alon Eitan Mar 14 '20 at 18:02

1 Answers1

1

The data you show isn't valid JSON and won't be readily parsable without modifying. JSON keys and values should be in quotation marks. The properties can be accessed either with a . or in a []. For multiple word keys, use brackets. Example:

a = {
  "valid property multiple words": "valid value 1",
  "validpropertyoneword": "valid value 2"     
};

a['valid property multiple words']; //<- evaluates to "valid value 1"
a.validpropertyoneword //<- evaluates to "valid value 2"

b = {
  invalid property: invalid value
}; //<- invalid JSON