It seems like your question may be a bit unclear, so here is a general response:
When you are dealing with an observable that emits arrays, there isn't much difference in how you handle the array whether it comes from an observable or not. After you receive the array, the process is essentially the same.
To access the first person, simply subscribe to the observable and retrieve the first element of the array like this:
getSomeObservableArrayOfPeople().subscribe(data => this.person = data[0]);
If the observable doesn't emit an entire array of people, but rather individual events for each person, you can utilize operators like
getSomeObservableOfPeople().skip(3).take(1).subscribe(data => this.person = person);
This specific code snippet will capture only the 4th person in the sequence, disregarding all others.
Tip: Remember to import operators such as skip
and take
explicitly to make them accessible.
In cases where the observable emits a series of person events (as mentioned in the example above), you can aggregate these events into an array using the scan
operator:
getSomeObservableOfPeople().scan(3).subscribe(data => {
if(data.length >= 3) {
this.person = data[2];
}
})
Each time a new person event is emitted, the callback function within the subscribe method will execute, combining the previous people with the latest person event.