mpsbhat mpsbhat - 11 months ago 53
AngularJS Question

angularjs filter based on particular key (exact match)

I want to filter an angularjs array say,

$scope.myObj = [

based particularly on
id = 1
. If i use

console.log($filter('filter')($scope.myObj, 1));

it will return all the object that contain
. 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.