AngularJS Tutorial - Filter object array by one of object properties








The following code shows how to use filter object array by one of object properties.

Example


<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
</head><!--   ww w . ja  v a  2  s . c  om-->
<body>
  <div ng-app="">
  <div ng-init="friends = [{name:'John', age:25}, {name:'Mary', age:28}]">
    I have {{friends.length}} friends. They are:
    <ul>
      <li ng-repeat="friend in fs = (friends | filter:{age:28})">
        [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
      </li>
    </ul>
      <pre>{{friends.length}}</pre>
      <pre>{{fs.length}}</pre>
  </div>
</div>
</body>
</html>

The code above is rendered as follows: