I am using the ‘jQuery.unique()’ function to put distinct array values from one array to another array but the values in the 2nd array does not seem to contain distinct values.
var nonuniqueArray = ['AMI:8244','AMI:29126','AMI:31591','AMI:31591','AMI:31591','AMI:31591','AMI:29126'];
uniqueArray = $j.unique(nonuniqueArray);
alert (uniqueArray);
Values alerted are: AMI:29126,AMI:31591,AMI:29126,AMI:8244
I noticed that if similar values in the array are grouped together, then it works fine, for e.g if ‘AMI:29126’ are grouped together, it seems ok.
Any suggestion on what’s wrong with the above code is most welcomed.
Many many thanks 🙂
here’s how you could do this with regular Array methods, but i would note that indexOf() is a newer array method and won’t work in IE7 or earlier but is easily duplicated with 1 loop