1

An object is being returned from the API and I want to reach the key "official-artwork", but I cannot reach the key "official-artwork" because of the - sign.

dream_world: {value}
home: {value}
official-artwork: {value}

When I type in js terminal, I get "item?.sprites.other.official-artwork" error, how can I solve it?

Andy
  • 53,323
  • 11
  • 64
  • 89
  • There are already multiple questions and answers on this topic, like [here](https://stackoverflow.com/questions/13869627/unable-to-access-json-property-with-dash) or [here](https://stackoverflow.com/questions/10148423/json-contains-minus-char-is-this-valid-standard). – ahuemmer May 21 '22 at 07:49

2 Answers2

0

try this:

item?.sprites.other['official-artwork']
Yasin Br
  • 1,313
  • 1
  • 3
  • 16
0

Put it in block & quotes:

item?.sprites.other["official-artwork"]
John Detlefs
  • 565
  • 4
  • 16