I'm working on a project that involves displaying data from an external Json file on my site. However, I'm facing an issue where I need to limit the display to only 5 items.
const displayCharacters = (characters) => {
characters.sort((a, b) => {
return a.rate - b.rate;
});
characters.sort((a, b) => b.rate - a.rate);
characters.forEach(() => {
const htmlString = characters
.map((character) => {
return `
<div class="col-6 my-2" onClick="addToCart(${character.id})"></div>
<div class="menu card my-3" style="width: 120px">
<div class="card-body">
<h5 class="menu-name">${character.nama}</h5>
<p> ${character.harga}</p>
</div>
</div>
</div>
`;
})
.join('');
charactersList.innerHTML = htmlString;
});
};
loadCharacters();
If anyone could offer assistance, it would be greatly appreciated.