Your problem is that you are redefining the HTML of the item after each iteration (loop). This will only make the last ID of the array be shown, since all previous ones have been reset by the following iteration.
So instead of redefine the content, you should simply add the data generated in each iteration to the previously created data.
See your problem in a slightly simpler example:
const $list = $('#my-list')
const ids = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
for (let i = 0; i < ids.length; i++) {
const id = ids[i].id
const html = `<li>${id}</li>`
console.log('ID atual:', id, ' | HTML atual:', html)
// Note que, ao invés de você acrescentar o HTML gerado ao final da lista,
// você simplesmente está redefinindo todo o HTML definido anteriormente,
// ao usar o método .html().
$list.html(html)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="my-list"></ul>
To resolve this, as mentioned earlier, you need to add the HTML generated to final of the list. For this, we will use the method append
jQuery. So:
const $list = $('#my-list')
const ids = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
for (let i = 0; i < ids.length; i++) {
const id = ids[i].id
const html = `<li>${id}</li>`
console.log('ID atual:', id, ' | HTML atual:', html)
// Agora, ao invés de redefinir o HTML após cada iteração, estamos simplesmente
// acrescentando o HTML gerado ao conteúdo, já existente, da lista:
$list.append(html)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="my-list"></ul>
So, in your code, you must change the html
(replacing existing HTML with a new HTML) by append
(adding a new HTML to an existing HTML). From:
$(".resultApi").html(dados);
To:
$(".resultApi").append(dados);
At the beginning of your function put a
console.log(getApi);
and put the result of this in your question– Sorack