Fetching Data from API for Dummies (JavaScript).

Fetching Data from API for Dummies (JavaScript).

ยท

1 min read

Fetch API + for of + async/await

we would not be using Promise.all and Promises chaining

const urls = [
  'https://jsonplaceholder.typicode.com/users',
  'https://jsonplaceholder.typicode.com/posts',
  'https://jsonplaceholder.typicode.com/albums',
];
async function getDatafromAPI(){
  const dataInArray = urls.map(url=>fetch(url));
  for await (let data of dataInArray){
        const dataConvetedtoObject=await data.json()
        console.log(dataConvetedtoObject)
  }
}

getDatafromAPI()

Result

Screenshot (139).png

Thankyou for Reading,