After getting data from OpenWeatherMap, I'm having trouble filtering it

Here’s my CodePen. I got the data from the API, but now when I try to filter it, nothing works. Could someone help me with this, please?

There’s a couple of issues going on. First, the ‘temp’ variable on line 16 is undefined. Second, in line 16 you’re comparing ‘val.main’ (an object) to some other value (‘temp’ which as of right now is undefined) so the result will always be false, even if temp holds an object. In JS you can’t check for object equality using the == sign. It will always return false even if the 2 objects have the same key: value pairs.

So this is the output from the JSON call:



How do I get the data that is inside of the array? I want to get the temperature information out of the array and into a variable so I can display it in html.

I didn’t use that API but my guess is that it’s something along the lines of:

(looking at the output you posted above (which is an object, not an array)):

var temperature=data.temp