Help with weather api project

Help with weather api project
0

#1

When calling the weather type from api, why do I have to use the array of 0?

var api =“https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139”;
var weatherType = data.weather[0].main;

Instead of

var weatherType = data.weather.main;


#2

Because the weather property has a value of an array that encloses the object, and to get the contents of an array you have to refer to the indices of an array. Your example (var weatherType = data.weather.main) would work if the weather property had an object value that was not enclosed in an array, i.e. if you had

data = {
weather: 
{
id: 800,
main: "Clear",
description: "clear sky",
icon: "https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F01n.png?1499366020783"
}
}