I have a foreach
that prints all categories of a JSON
. How do I get him to only get up to 3 position and stop loop
? The issue is that I want to create a ul
with 3 categories in the menu and create another li
with a sub-menu listing the rest of them. If it is 10 categories then it lists the first 3 in the first 3 li
and then the 7 in this submenu within the li
following.
Follow the code:
var quantidadeElementos = retorno.data.length;
var i = 0;
while (i <= quantidadeElementos)
{
if (i == 3)
{
retorno.data.forEach(function(item)
{
console.log(item.nome);
})
break;
}
i++;
}