0

I'm like to count the total values in my array but I like to skip the same value

my array example, my real array will have about 1000 values.

json2=[aaa,aaa,aaa,aaa,bbb,bbb,bbb,ccc,ccc,ccc,ccc,ccc,ddd,ddd,ddd,eee,eee,fff];

and i want my count result to be

var countBoxID=6;

i only got

for(i in json2){

countBOXID ++

    }
子維 宋
  • 85
  • 1
  • 11

1 Answers1

0

You can make use of this function:

function GetUnique(inputArray)
{
    var outputArray = [];

    for (var i = 0; i < inputArray.length; i++)
    {
        if ((jQuery.inArray(inputArray[i], outputArray)) == -1)
        {
            outputArray.push(inputArray[i]);
        }
    }

    return outputArray;
}
V31
  • 7,626
  • 3
  • 26
  • 44