'Using fetch to log/output json values
I'm trying to fetch values from JSON, see below. I need the values for the very last "year", "month", "day", "cycle", "trend" in the object
{"co2":[{"year":"2012","month":"1","day":"1","cycle":"392.92","trend":"391.50"},
...
,{"year":"2022","month":"2","day":"20","cycle":"418.63","trend":"416.80"}]}
I've tried the following script, but it logs [object Object]. Any ideas? Thanks in advance.
async function loadnums() {
const response = await fetch('https://global-warming.org/api/co2-api');
const nums = await response.json();
console.log(nums);
}
loadnums();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
