<!DOCTYPE html> <html> <head> <title>Fetch Example</title> </head> <body> <h2>User Data</h2> <table border="1" id="dataTable"> <tr> <th>Name</th> <th>Email</th> </tr> </table> <script> fetch('https://jsonplaceholder.typicode.com/users') .then(response => response.json()) .then(data => { const table = document.getElementById("dataTable"); data.forEach(user => { const row = table.insertRow(); row.innerHTML = `<td>${user.name}</td><td>${user.email}</td>`; }); }) .catch(err => console.log("Error:", err)); </script> </body> </html>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter