Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular filter if value not matched [duplicate]

I have an array data, I want to filter it into two array. One if id==100 and second if id!=100

$scope.if100 = $filter('filter')(data, { id: 100 })[0];
$scope.ifnot100 = ?
like image 576
om_jaipur Avatar asked Aug 30 '17 09:08

om_jaipur


1 Answers

You can use filter method from native javascript.

The filter() method creates a new array with all elements that pass the test implemented by the callback provided function.

$scope.if100=$scope.data.filter(function(item){
     return item==100;
});
$scope.ifnot100=$scope.data.filter(function(item){
     return !(item==100);
});

or from angularjs by passing a callback function.

$scope.if100 = $filter('filter')(data, function(item){ return item.id == 100;});
$scope.ifnot100 = $filter('filter')(data, function(item){ return item.id != 100;});
like image 111
Mihai Alexandru-Ionut Avatar answered Sep 27 '22 21:09

Mihai Alexandru-Ionut