I am trying to use array.splice to remove an object from my array, but my object position in the array is -1 so its not being removed. I think its because I am creating a new object every time, so the two object are not the same. Here is my code.
let selectedCurrency = new Currency(null, null, null, symbol, currency_code, false, false, currency_description, null);
if (event.checked) {
this.companyCurrencies.push(selectedCurrency);
} else {
console.log("original array: ",this.companyCurrencies);
console.log("selected currency: ",selectedCurrency);
let index = this.companyCurrencies.indexOf(selectedCurrency);
if (index === -1) {
return;
}
this.companyCurrencies.splice(index, 1);
console.log("array after spliced: ",this.companyCurrencies);
}
I am not sure how to get around this issue, any help would be much appreciated thanks.
this.companyCurrencies.splice(this.companyCurrencies.findIndex(item => item.code === currency_code), 1);