Im currently having some problems getting a distinct list of values from an array.
what i am looking for is something that will give me a count of distict values in the form
I have the following Array of Items
[{"Office":"abc", "Name":"ABC", "Total":0},
{"Office":"def", "Name":"DEF", "Total":11},
{"Office":"def", "Name":"DEF", "Total":1},
{"Office":"ghi", "Name":"GHI", "Total":1111}]
and i am looking for the following output which is a distinct list of Offices with the number of instances of each.
[
{"office":"abc","count":1},
{"office":"def","count":2},
{"office":"ghi","count":1}
]
The following i have tried is
ko.utils.arrayForEach(officeLines, function (item, indx)
{
var office = item.Office;
if (test[office] == null)
{
test.push({ office: office, count: 1 });
}
else
{
test["office"][office] += 1;
}
});
but this gives me a single item for each Office in the original array.