1234567891011121314151617181920212223242526 |
- const renderTableFromJSON = (parent, jsonObj) => {
- const tableConstruct = json => {
- let tableElement = '<table>';
- for (const row in json) {
- tableElement += `
- <tr>
- <td>${row}</td>
- <td>${json[row]}</td>
- </tr>`;
- }
- tableElement += '</table>';
- return tableElement;
- }
- fetch(`${jsonObj}`)
- .then(response => response.json())
- .then(luke => {
- parent.insertAdjacentHTML('beforeend', tableConstruct(luke));
- });
- }
- renderTableFromJSON(document.body, 'https://swapi.dev/api/people/1/');
|