From API Response to Readable Data: Fetch and JSON in JavaScript
Introduction In JavaScript, fetch() is used to request data from APIs. The data is usually returned in JSON format, which must be converted into a JavaScript object to be usable. How Fetch Works A ...

Source: DEV Community
Introduction In JavaScript, fetch() is used to request data from APIs. The data is usually returned in JSON format, which must be converted into a JavaScript object to be usable. How Fetch Works A request is sent to the API using fetch(). A response is received from the server. The response data (JSON) is converted into a JavaScript object. The data is accessed and used in the application. Basic Example fetch("https://jsonplaceholder.typicode.com/users") .then(response => response.json()) .then(data => console.log(data)); Understanding API Data Example JSON response: [ { "id": 1, "name": "Leanne Graham", "email": "[email protected]" } ] After conversion, the data can be accessed as a JavaScript object: console.log(data[0].name); console.log(data[0].email); Accessing Specific Values fetch("https://jsonplaceholder.typicode.com/users") .then(response => response.json()) .then(data => { console.log(data[0].name); console.log(data[1].email); }); Looping Through Data fetch("https: