maria maria - 15 days ago 4
AngularJS Question

Angularjs Split array by object result

I have a array with objects like this:

{
__v: 0,
_id: "5835ced6ffb2476119a597b9",
castvote: 1,
time: "2016-11-23T17:16:06.676Z",
userid: "57e0fa234f243f0710043f8f"
}


How can I make a new array that would filter them by the
castvote
- like an array containing the objects where
castvote
is 1, and one where
castvote
is 2?

Answer

You can do this in controller using $filter,

$scope.castvoteOne = $filter('filter')($scope.results, {castvote: 1});
$scope.castvoteTwo = $filter('filter')($scope.results, {castvote: 2});

DEMO