0

I am trying to parse through the JSON response from the OpenWeather API and I want to get the probability of precipitation, but the corresponding API response field is 'pop', so whenever I try to access it thinks that I am trying to use the .pop() method. How can I get Javascript to ignore the .pop() method and just let me use .pop to access the API?

My code:

ImageOfMyCodeThinkingPopIsACallToAMethod

The applicable portion of the JSON response:

TheApplicablePortionOfTheJSONResponse

Thank You

D M
  • 5,769
  • 4
  • 12
  • 27
  • Is it actually throwing an error or is it just that the syntax highlighting wrong? Unless `hourly[i]` is an array, you shouldn't have an issue with it actually trying to reference `Array#pop`. If it's throwing an error, use `response.hourly[i]['pop']`. See [JavaScript object: access variable property by name as string](https://stackoverflow.com/questions/4255472/javascript-object-access-variable-property-by-name-as-string) – D M Feb 04 '22 at 20:49
  • 1
    Please add a [mcve] to your question instead of screenshots. – Kosh Feb 04 '22 at 20:55
  • 1
    Yes it was throwing an error, but your idea to access it as a string worked perfectly. Thank you so much! – Nathan Johnson Feb 04 '22 at 20:56

1 Answers1

0

You could try this: response['pop'] but after all OpenWeather API needs to fix this. Maybe send them an email, and let them know, but this needs to be fixed from their part since you can't ignore built in methods

ImDarkk
  • 215
  • 2
  • 10