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

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

#1

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?


#2

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.


#3

So this is the output from the JSON call:

{“coord”:{“lon”:-77.15,“lat”:39.08},“weather”:[{“id”:800,“main”:“Clear”,“description”:"clear

sky",“icon”:“01d”}],“base”:“stations”,“main”:{“temp”:279.28,“pressure”:1011,“humidity”:35,“temp_min”:275.15,“temp_max”:282.15},“visibility”:16093,“wind”:{“speed”:11.3,“deg”:290,“gust”:21.6},“clouds”:{“all”:1},“dt”:1479663300,“sys”:{“type”:1,“id”:1332,“message”:0.2394,“country”:“US”,“sunrise”:1479643112,“sunset”:1479678614},“id”:4367175,“name”:“Rockville”,“cod”:200}

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.


#4

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