-1

Some of the keys have the format "something-something" and the JS code doesn't allow me to use them that way, I need a way around that

for example, I have this line, where I am resetting a React state

data.sprites.official-artwork.front_defaul
  • see: [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation) – pilchard Apr 26 '23 at 22:37
  • Does this answer your question? [JavaScript object: access variable property by name as string](https://stackoverflow.com/questions/4255472/javascript-object-access-variable-property-by-name-as-string) – pilchard Apr 26 '23 at 22:38
  • and [Accessing an object property with a dynamically-computed name](https://stackoverflow.com/questions/4244896/accessing-an-object-property-with-a-dynamically-computed-name) – pilchard Apr 26 '23 at 22:44

1 Answers1

0

You can simply use the bracket notation.

For your example:

data.sprites["official-artwork"].front_defaul
yoadev
  • 149
  • 6
  • Flag as [duplicate](https://stackoverflow.com/questions/4244896/accessing-an-object-property-with-a-dynamically-computed-name). – pilchard Apr 26 '23 at 22:42