I want to filter an angularjs array say,
$scope.myObj = [
{id:1,name:'foo'},
{id:2,name:'bar'},
{id:10,name:'quad'},
{id:13,name:'cad'}
]
based particularly on id = 1. If i use
console.log($filter('filter')($scope.myObj, 1));
it will return all the object that contain 1. How can i restrict to filter only required object?
EDIT: It can solved by using `true for exact match based on answer below.
console.log($filter('filter')($scope.myObj, {id: 1}, true));
Execute below code to filter data by ID column:
var filterObjList=$filter('filter')($scope.myObj, {id:1}, true);
if(filterObjList && filterObjList.length>0)
return filterObjList[0];
If you want to filter the list by name then replace "Id" with "name" and pass the value in single inverted commas.
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