Rahul
Rahul

Reputation: 55

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.

Upvotes: 0

Views: 159

Answers (1)

Đăng Khoa Đinh
Đăng Khoa Đinh

Reputation: 5411

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

Upvotes: 2

Related Questions