Lesson 26: Using fetch() to Get Data
Using fetch()
The fetch() function lets you request data from an API endpoint.
fetch("https://api.example.com/data")
.then(response => response.json())
.then(data => {
console.log(data);
});
Always handle errors using .catch().