I know similar questions have been asked before, but I tried every answer and nothing worked for me. I am creating my array on every click on some of buttons with class ognjen. So it looks like this:
<button type="button" name="10208823390691752,1317727711586522" value="All contacts" class="btn btn-default ognjen">All contacts</button>
<button type="button" name="10207252567926988,1294280923934896" value="Men" class="btn btn-default ognjen">Men</button>
<button type="button" name="10208823390691752,10207252567926988" value="Women" class="btn btn-default ognjen">Women</button>
<button type="button" name="1317727711586522,1294280923934896" value="Segment 1" class="btn btn-default ognjen">Segment 1</button>
So this is how I managed to make one array with values of all clicked elements:
$(document).ready(function() {
        var clickedButtons = new Array();
        var numUsers= new Array();
        $('button.ognjen').click(function() {
            var index = clickedButtons.indexOf(this.value);
            if (index === -1){
                clickedButtons.push(this.value);
                numUsers.push(this.name);//value not found so push it
                }else {
                clickedButtons.splice(index, 1);
                numUsers.splice(this.name);// value found so remove it
            }
            var tryIt=numUsers.join();
            var picker=tryIt.split(', ');
            console.log(picker);
});
So picker is now an array that may look like this, after clicking certain buttons:
["10207252567926988,1294280923934896,10208823390691752,1317727711586522,1294280923934896"]
Now, I would like to remove all duplicate elements from this array. Tried answers from these questions:
- How to remove duplicates from array - javascript
- Easiest way to find duplicate values in a JavaScript array
- Remove duplicate elements from array using JavaScript
- Remove Duplicates from JavaScript Array
And none of them worked. I think it may be due to dynamics of making this piker array. Please help, I'm struggling whole day with this problem.
 
     
    