Search code examples
node.jspokeapi

How to target a property of an object returned by an api that is the format "XYZ-ABC"?


I am trying to fetch an img returned by the api(pokeapi.co) which is a property of an object 'official-artwork'. I am getting a following error:

 UnhandledPromiseRejectionWarning: ReferenceError: artwork is not defined

I am not sure how to fetch results out of objects named like that or if its even possible to retrieve info out of these objects.


Solution

  • I guess you're using data.official-artwork (dot notation) to retrieve the official-artwork property from data. Simply replace by data["official-artwork"] (bracket notation)

    You can read more about property accessors here