Currently learning Javascript and working on a project that involves retrieving data from a weather API. Encountered a simple issue that I need help with. Here is the data I managed to fetch so far:
{coord: {…}, weather: Array(1), base: "stations", main: {…}, visibility: 9656, …}
coord: {lon: -76.13, lat: 43.04}
weather: Array(1)
0: {id: 500, main: "Rain", description: "light rain", icon: "10d"}
length: 1
__proto__: Array(0)
base: "stations"
main: {temp: 281.12, feels_like: 274.24, temp_min: 280.37, temp_max: 282.04, pressure: 1004, …}
visibility: 9656
wind: {speed: 8.2, deg: 310}
rain: {1h: 0.25}
clouds: {all: 90}
dt: 1587324361
sys: {type: 1, id: 5965, country: "US", sunrise: 1587291309, sunset: 1587340289}
timezone: -14400
id: 0
name: "Syracuse"
cod: 200
__proto__: Object
I am trying to access the "Rain" value under the weather property. However, since it's within an array, I'm unsure how to retrieve it. For instance, if I use:
data.visibility
I will get back 9656. But when I try:
data.weather.0
or data.weather.["0"]
I encounter the error: Uncaught SyntaxError: Unexpected number. Even if I manage to avoid this error, how can I specifically target the element "Rain" in the Array?
I apologize if this is a simple issue, as I'm having difficulty finding a solution due to the specific terminology used in my searches.