I am trying to swap two items in the observable array. I know how to do it in the normal array. I tried the same way but it doesn't change the value.
Here is what I tried,
swapObservableArray() {
let index;
// get the index
this.productss$
.pipe(findIndex((a) => a.id === 5))
.subscribe((a) => (index = a));
// swap the items
[this.productss$[2], this.productss$[index]] = [
this.productss$[index],
this.productss$[2],
];
this.productss$.subscribe((a) => console.log(a));
}
Is that what you tried to achieve? Please pay attention that I also modified how
productss$is initialized.Stackblitz code