Trying to filter through an array in Angular, and filter out all objects of a certain property
I have an array like this:
[
{
"group":"Group A",
},
{
"group":"Group A",
},
{
"group":"Group B",
},
{
"group":"Group B",
}
{
"group":"Group C",
},
{
"group":"Group C",
}
]
...and I want to write a function to return an array with only Group A and B (not Group C).
So far this is what I have:
function filterStandings() {
for (var i = 0, len = $scope.originalArray.length; i < len; i++) {
$scope.filteredArr = [];
if (originalArray[i].group !== "Group C") {
$scope.filteredStandingsArr.push($scope.originalArray[i]);
}
}
return $scope.filteredArr;
};
Then I when I try to display this array in my view by calling the filterStandings() function, nothing shows up.
Can anyone help?
{ "group":"Group B", }