I am creating a comparison between popular javascript frameworks and need to create an HTML element for each object returned from an api.
const frameworks = [
{
name: "angular"
},
{
name: "ember"
},
{
name: "react"
},
{
name: "vue"
}
];
To keep it simple I just have an array of objects (this is simplified for readability).
I have a function to loop over this array and for now it's just printing the name of the framework to the console. If I want to create this HTML element (just a bootstrap card) for each item in the loop, what would be the best way to do it?
frameworks.forEach(fw => {
console.log(fw);
});
Just a very simple forEach function.
<div class="card" style="width: 18rem;">
<img class="card-img-top" src=".../100px180/?text=Image cap" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
<div class="card-body">
<a href="#" class="card-link">Card link</a>
<a href="#" class="card-link">Another link</a>
</div>
</div>
I am trying to do this in vanilla JS otherwise I would just use React. This just seems a bit cumbersome. Is the best way to do it is to scaffold this as a template with the createElement() function?