0

I am trying to ensure that my list does not contain an object that has just been instantiated. In it's current form the code lets any element into the list. Any suggestions would be greatly appreciated, thank you.

if(!this.$store.state.testCoins.includes(coinyBoi)){
  this.$store.commit('pushCoin', coinyBoi);
} else {
  console.log("DUPLICATE DETECTED!");
};
Rengers
  • 14,911
  • 1
  • 36
  • 54
  • This would only detect a duplicate when the array has the *same* object reference for `coinyBoi`. If however you are expecting to detect any object that has the same properties, you need to compare those properties one by one. Possibly `JSON.stringify` may help you out. – trincot Jun 17 '19 at 19:10
  • Thank you, that sounds logical and should solve the problem. Will update here when it works! – opINTENSIFY Jun 17 '19 at 19:21

0 Answers0