Answer the question
In order to leave comments, you need to log in
Why is an error thrown ( Uncaught TypeError: Cannot read property '0' of undefined ) and how to fix it???
Help me solve the problem, I get the error Uncaught TypeError: Cannot read property '0' of undefined
I'm working with the weather API, the error is in the same line
' Weather: ' + res.weather[0].main + ''+
function openModal(res) {
if(Object.getOwnPropertyNames(res).length === 0) {
contentString = 'To much long, come closer.';
} else {
contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<div><b>Place: </b><span id="place"> ' + res.name + '</span> </div>'+
'<p><b>Weather:</b> <span id="weather">' + res.weather[0].main + '</span></p>'+
'<p><b>Temperature:</b> <span id="temperature">' + (res.main.temp - 273.15).toFixed(offset = 0) +'</span>° C</p>'+
'<p><b>Wind speed:</b> <span id="wind">' + res.wind.speed + '</span> ms</p>'+
'<p><b>Humidity:</b> <span id="humidity">' + res.main.humidity + '</span>%</p>'+
'</div>';
}
infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(map, marker);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question