Filter an array of Observable Object using RxJS

map((reports : IReport[]) => reports.filter(p => p.reportName === name))
findItemsByParentId(id: number): Promise<Item[]> {
  return new Promise<Item[]>((resolve, reject) => {
    this.localStorage.getItem('items')
      .pipe(map((items: Item[]) => items.filter((item: Item) => item.parentId === id)))
      .subscribe((value: Item[]) => {
        resolve(value);
      });
  });
}

References
https://www.learnrxjs.io/operators/transformation/map.html
https://rxjs.dev/api/operators/map
https://stackoverflow.com/questions/52263374/angular-rxjs-observable-filter-on-array-of-objects

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.