С этим кодом
this.initialProduct = this.product;
вы присваиваете this.initialProduct
ту же переменную, расположенную в индексе памяти, связанном с this.product
.Это потому, что this.product
указывает на адрес памяти, а с предыдущей операцией вы копируете только адрес памяти.Поэтому this.product
и this.initialProduct
указывают на одну и ту же переменную.
Вам необходимо создать другой массив и скопировать this.product
значения в this.initialProduct
(новый массив).
Вы можетесделать это различными способами.Например:
// this.initialProduct = this.product;
this.initialProduct = {
tags: Array.from(this.product.tags)
}
или
// this.initialProduct = this.product;
this.initialProduct = {
tags: this.product.tags.concat()
}
или
// this.initialProduct = this.product;
this.initialProduct = {
tags: this.product.tags.slice()
}