Find object by its property in array of objects with AngularJS way Find object by its property in array of objects with AngularJS way angularjs angularjs

Find object by its property in array of objects with AngularJS way


you can use angular's filterhttps://docs.angularjs.org/api/ng/filter/filter

in your controller:

$filter('filter')(myArray, {'id':73}) 

or in your HTML

{{ myArray | filter : {'id':73} }}


How about plain JavaScript? More about Array.prototype.filter().

var myArray = [{'id': '73', 'name': 'john'}, {'id': '45', 'name': 'Jass'}]var item73 = myArray.filter(function(item) {  return item.id === '73';})[0];// even nicer with ES6 arrow functions:// var item73 = myArray.filter(i => i.id === '73')[0];console.log(item73); // {"id": "73", "name": "john"}