#Behavior Subject & Observable Array: Find object by index, update specific properties ?

3 messages · Page 1 of 1 (latest)

coarse coyote
#

I have a Behavior Subject and Observable like so:
private selectedItemSubject = new BehaviorSubject<ItemDto[]>([]) public selectedItemObservable = this.selectedItemSubject.asObservable();

How do I find an object by index, make some updates to that object's properties and then update so that a component subscribed to the observable can get those changes? The observable/behavior subject exist inside a service, so I would like to handle this in the service.

warm sluice
#

That's kinda the wrong way to think about it

#

But short answer:

// copy the latest subject value
const array = [...sub.value]
// change it
array[x] = y
// "set" the new one
sub.next(array)