#Filter By ID

2 messages · Page 1 of 1 (latest)

candid trellis
#

How do I filter by id

  bank!: any;
  isLoaded = false;
  cid:any=''
  bArray:Bank[]=[];
  
  getAllBanks()
  { 
    this.bankService.fetchAllBanks().subscribe(res => this.bArray=res);
    this.bArray.filter(obj => obj.customerId===this.cid);
    this.isLoaded=true;
  
  }```
stuck vortex
#
(1) this.bankService.fetchAllBanks().subscribe(res => 
    (2) this.bArray=res
    );

(3) this.bArray.filter(obj => obj.customerId===this.cid);

beware of asynchronous code

(1) is asynchronous code
it executes code whose response will come a few milliseconds later (http, ...)
(3) it filters this.bArray but this one is empty
(2) a few milliseconds later: this.bArray=res is executed !

do you see the problem ?