0

I have two observable arrays: First array object observable

 array1= Observable.of({
      data: [
      {
          name: 'test',
          lastname: 'last'
        },
         {
          name: 'test1',
          lastname: 'last1'
        }
      ]
    }).map(res => {
      return res.data;
    });



// Second Observable:
    array2 = Observable.of('test1');

Expected Result from the above two array is that wherever firstname is matching with array2 value, get the lastname from that object.

//Expected Result: 
object3=Observable.of('last')
FrontEndDeveloper
  • 99
  • 1
  • 2
  • 11

1 Answers1

0

It looks like you're using RxJS 5.4 so you could do it like this for example:

Observable.combineLatest(array1, array2)
  .map(([users, name]) => {
    const user = users.find(u => u.name === name);
    return user ? user.lastname : null;
  })
  .subscribe(console.log);

See live demo: https://stackblitz.com/edit/rxjs5-4nyq3s?file=index.ts

martin
  • 93,354
  • 25
  • 191
  • 226