Angular / ionic

Hi, I have a ngFor how can I only retrieve the latest or last index item? Thankyou.

Hi @RobertLow

Don’t know about index but you can find element using below code :

heroes = [
    {id: 1, name:'Superman'},
    {id: 2, name:'Batman'},
    {id: 5, name:'BatGirl'},
    {id: 3, name:'Robin'},
    {id: 4, name:'Flash'}
];
<tr *ngFor="let hero of heroes; let first = first; let last = last" >
    <td *ngIf="last" >{{hero.name}}</td>
</tr>
2 Likes

Hi, with tested your code out this is the result,

falsetrue Superman
falsefalse Batman
falsefalse BatGirl
falsefalse Robin
truefalse Falsh

What does it mean? Sorry I don’t really get it like for this example I would only like to display Flash as it is the last item. Thankyou

Have tried using ngIf to elimate the unwanted. Not sure if this is the best way, it works.

Please check it will update