I'm working with AngularJS. I have an array of objects like this:
$scope.documents =
[
{
"id": "221",
"activate": "t"
},
{
"id": "1",
"activate": "t"
},
{
"id": "2",
"activate": "t"
},
{
"id": "221",
"activate": "t"
},
{
"id": "5",
"activate": "t"
},
{
"id": "221",
"activate": "t"
},
{
"id": "221",
"activate": "t"
},
{
"id": "7",
"activate": "t"
},
{
"id": "8",
"activate": "t"
},
{
"id": "9",
"activate": "t"
},
{
"id": "221",
"activate": "t"
}
]
I need an angularjs function to count the number of repeated values in the array of objects.
Something like this:
$scope.count = function(param) {
angular.forEach($scope.preguntas, function(value, key) {
if (value.id == param){
........
........
}
});
};
but I'm not sure how I can do.
I hope the result is something like this:
count(221);
5
Any of you have any suggestions please?