title: How to get last object from array of object based on condition in angular 8
body: <p>I have some objects, that I am receiving one after another using <code>settimeout</code> function and then pushing every time into array to populate into a table. That is coming dynamically in my project but just for reference I am using <code>settimeout</code> and hard coding here.  </p>
  
  <p>Now my problem is, whenever I am receiving data using <code>settimeout</code>, I need to get last object by filtering with vehicle_number (if it contains same vehicle_number, I need to get last object of that vehicle_number) and need to populate/push into table again. Here is the code I have tried.</p>
  
  <h2>home.component.html</h2>
  
  <pre><code>&lt;div&gt;
  &lt;table&gt;
  &lt;tr *ngFor="let x of groupList"&gt;
  &lt;td&gt;{{x.vehicle_number}}&lt;/td&gt;
  &lt;td&gt;{{x.status}}&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h2>home.component.ts</h2>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  
  
  @Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.css']
  })
  
  export class HomeComponent implements OnInit {
  imageSource :any;
  statusdata1: any;
  vehicle_number:any;
  groupList:any = [];
  
  constructor() {}
    ngOnInit() {
       /* First data */
      this.statusdata1 = {"vehicle_number":1,"status":"red"};
       this.groupList.push(this.statusdata1);
       console.log(this.groupList);
  
       /* second data */
      setTimeout (() =&gt; {
          this.statusdata1 = {"vehicle_number":1,"status":"green"};
           this.groupList.push(this.statusdata1);
  
           console.log(this.groupList);
        }, 5000);
     /* Third data */
  
        setTimeout (() =&gt; {
          this.statusdata1 = {"vehicle_number":2,"status":"yellow"};
           this.groupList.push(this.statusdata1);
           console.log(this.groupList);
        }, 10000);
  
  
    }
  
  }
  </code></pre>