Flash Builder 4, AS3.
In an ArrayCollection need to count the records in a field, for example need to know how many users have age of 25. This is the ArrayCollection dataProvider for my DataGrid.
In SQL is easy, just need the command: select age, count (age) from employees where age = '25';
But ArrayCollection tried several ways and could not, could someone help me?
Thank you very much!
This should work assuming the ArrayCollection
has objects with a field age
:
var ac:ArrayCollection = new ArrayCollection([ { "name":"test1", "age":25 }, { "name":"test1", "age":20 }, { "name":"test1", "age":25 } ]);
var count:int = 0;
for each (var item:Object in ac)
{
if (item.age == 25)
++count;
}
trace(count);