How to run a infinite angular forEach loop in angularjs? <pre><code>InstitutionStructure.teamHierarchy().then(function(response) { $scope.hierarchyList = response.data; $scope.hierarchyListsData = _.where($scope.hierarchyList, {reportingMemberId: null}); angular.forEach($scope.hierarchyListsData, function(value1, key1) { value1.teamMember = []; angular.forEach($scope.hierarchyList, function(value2, key2) { if(value1.teamMemberId === value2.reportingMemberId) { value1.teamMember.push(value2); } }) }) </code></pre> <p>From the above code I have loaded my hierarchyListsData continuously and I have to fetch list that corresponds to have teamMemberId which is equal to reportingMemberId till the object has no other corresponding values. Please help to find the solution.</p>