2
Consume an Api whose return is an array with 10 objects inside, I want to show on the screen only the first five of the array, which are always the latest in the Api, as you can see in the code below, in the test with the while I got 5, but only the last 5, I tried to give a reverse()
before the
length, However, he added to the list:
let api = [
{
"id": 44,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Filtro de data cartão virtual ",
"institutionName": "0021 30** **** 7404",
},
{
"id": 39,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Testes mais testes",
"institutionName": "0721 30** **** 7893",
},
{
"id": 27,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Transferi 100,00 reais",
"institutionName": "0221 20** **** 4895",
},
{
"id": 26,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Transf. de 350 reais",
"institutionName": "0021 30** **** 7404",
},
{
"id": 25,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Transferência de Duzentão",
"institutionName": "0221 30** **** 0114",
},
{
"id": 11,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "fdfdfd",
"institutionName": "0221 20** **** 0843",
},
{
"id": 9,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Transferindo 400",
"institutionName": "0721 30** **** 7893",
},
{
"id": 8,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Teste 200",
"institutionName": "0321 20** **** 1995",
},
{
"id": 7,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "recarga 100",
"institutionName": "0021 30** **** 7404",
},
{
"id": 5,
"owner": null,
"ownerName": null,
"bankAccountId": "e8b2eb06-0df8-43bb-8012-ea42b63fb91f",
"description": "Primeira Recarga",
"institutionName": "0221 20** **** 0843",
}
]
let i = 5;
while(i < api.length) {
console.log(api[i]);
i++;
}
How can I take only the first five results of the array, and save them if possible in an array, because I am using in a table with Angular and do a ngFor.
try changing Let i = 5; for Let i = 0; and while(i < api.length) for while(i < 5)
– Sumback
@Sumback, post a reply, it is good to get registered on the site.
– LeAndrade