Reputation: 197
This is my code:
if(data.error) {
msg1.textContent=data.error
}
else {
msg1.textContent=data.location
msg2.textContent=data.forecast
console.log(data.forecast)
}
})
However, I'm not getting output for msg2
. It displays [object Object]
. But the same when used with console.log(data.forecast)
displays the below:
How can I display the values in data[0]
ie. partly cloudy
Upvotes: 0
Views: 85
Reputation: 351
Since data is logging an object with property called data. You can get the value like this: data.forecast.data[0]
if you want display all the values inside data array you can use join method in order to display values seperated by comma like this: data.forecast.data.join(", ")
Upvotes: 2