Я привел вам пример, используя новый Fetch API , написанный на обычном JavaScript с нулевыми зависимостями.
const root = 'https://jsonplaceholder.typicode.com';
const asyncFetchPosts = async() => (
fetch(`${root}/posts`)
.then(res => res.json())
);
const start = async() => {
const posts = await asyncFetchPosts();
const tableHead = document.getElementById('myTableHead');
const tableBody = document.getElementById('myTableBody');
// Let's read all property keys from the first post
// Array: [userId, id, title, body]
const keys = Object.keys(posts[0]);
// Add table head row
const tableHeadRow = tableHead.insertRow(tableHead.rows.length);
// Iteare over keys to create the header
keys.forEach((key, i) => {
const newCell = tableHeadRow.insertCell(i);
const newText = document.createTextNode(key);
newCell.appendChild(newText);
});
// Iteare over all posts
posts.forEach(post => {
const newRow = tableBody.insertRow(tableBody.rows.length);
// Now iterate over the keys for each post
keys.forEach((key, i) => {
const newCell = newRow.insertCell(i);
const newText = document.createTextNode(post[key]);
newCell.appendChild(newText);
})
});
}
// Call start
start();
<table id="myTable" border="1">
<thead id="myTableHead">
</thead>
<tbody id="myTableBody">
</tbody>
</table>