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 = ?
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;});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With