how to store json data in variable from fetch js code example
Example 1: getdata from fetch api into variable
function getData(url, cb) {
fetch(url)
.then(response => response.json())
.then(result => cb(result));
}
getData(url, (data) => console.log({ data }))
Example 2: getdata from fetch api into variable
async function getData(url) {
const response = await fetch(url);
return response.json();
}
const data = await getData(url);
console.log({ data })