Having an issue with my project when it comes to adding a duplicate value to an array on a click event.
when I push the clicked item's value to the array openedCards.push(card);
the code allows for multiple item values to be added to the array thus creating a matched value with a single item.
I have tried wrapping this code like so if ($.inArray(card, openedCards) < 0)openedCards.push(card);
i see that the match class is no longer being added to matching pairs, or any values for that matter.
here is the Here is the jsfiddle
In Excel, there are several ways to filter for unique values—or remove duplicate values: To filter for unique values, click Data > Sort & Filter > Advanced. To remove duplicate values, click Data > Data Tools > Remove Duplicates.
With vanilla javascript you can do this like the following:
if (array.indexOf(value) === -1) array.push(value);
Where array
is your array of value
's that you don't want duplicates of.
Or, you can use the following es6 syntax:
if (array.includes(value) === false) array.push(value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With