Answers for "async await syntax for fetching data in javascript"

0

fetch js async await

async function getData() {
   const response = await fetch('https://jsonplaceholder.typicode.com/users');
            const data = await response.json();
            const {
                id = data[1]['id'],
                name = data[1]['name'],
                username = data[1]['username'],
                email = data[1]['email'],
                address = data[1]['address']
            } = data
            console.log(data)
            console.log(`ID: ${id}`);
            console.log(`Name: ${name}`)
            console.log(`Email: ${email}`)
            console.log(`Username: ${username}`)
            console.log(address)
            console.log('Street: ' + address.street)
            console.log(address.suite)
        }
	getData();
Posted by: Guest on January-04-2022
0

how to Fetch API to Get Data using async await and then catch in javascript

// how to Fetch API to Get Data using async await and then catch in javascript
async function getFetchData(url){
    await fetch(url)
    .then(response => response.json())
    .then(data => console.log(`Id: ${data[99].id}, Title: ${data[99].title}`))
    .catch(error => console.log(error))
}
getFetchData(apiUrl);
Posted by: Guest on December-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language