Answers for "getdata function with fetch"

0

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 })
Posted by: Guest on September-23-2020
0

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 }))
Posted by: Guest on September-23-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language