How to count number of occurrences in array?

I need to know the amount of times true appears in an array.

I’ve tried this:

var myarray = Array(true, true, false);
var mycount = myarray.Count(true);

But it doesn’t work.

I know I could do this with a function, but I assume there’s an easier way…

var trueCounts = 0;
for (i = 0;i<array.length;i++)
{
  if (array[i] == true)
    trueCounts++;
}
Debug.Log(trueCounts)

does that work. I don’t think there is a way to do what your asking without doing something like that code above (ie. no predefined function)

Thanks, it’s disappointing that this isn’t a built in function, since I use this type of thing a lot. But I already wrote a function to perform the same task:

static function Count(myarray : Array, mybool : boolean){
	//counts occurences of boolean in array
	var mycount = 0;
	for (var n = 0; n < myarray.length; n++){
		if (myarray[n] == mybool) mycount ++;
	}
	return mycount;
}