Skip to content

Latest commit

 

History

History
54 lines (54 loc) · 1.5 KB

family-night.md

File metadata and controls

54 lines (54 loc) · 1.5 KB
<title>API Response Table</title> <script> async function fetchData() { const url = 'https://nfl-team-stats1.p.rapidapi.com/teamStats'; const options = { method: 'GET', headers: { 'X-RapidAPI-Key': '31c2c9240dmshb093261393c2f95p1ac6bajsn3bf7b947282a', 'X-RapidAPI-Host': 'nfl-team-stats1.p.rapidapi.com' } }; try { const response = await fetch(url, options); const result = await response.json(); console.log(result); // Create table const table = document.createElement('table'); table.border = '1'; // Create table header const headerRow = document.createElement('tr'); for (const key in result[0]) { const headerCell = document.createElement('th'); headerCell.textContent = key; headerRow.appendChild(headerCell); } table.appendChild(headerRow); // Create table rows for (const item of result) { const row = document.createElement('tr'); for (const key in item) { const cell = document.createElement('td'); cell.textContent = item[key]; row.appendChild(cell); } table.appendChild(row); } // Clear previous table, if any const outputDiv = document.getElementById('output'); outputDiv.innerHTML = ''; // Append table to the HTML document outputDiv.appendChild(table); } catch (error) { console.error(error); } </script> Fetch Data