How to iterate through angular $scope variables with a loop
问题 I want to iterate through $scope variables with a for loop like this. In this example the $scope object includes an object accounts inlcuding 5 objects, whose names are numbers from 1 to 5. Each of them has a name. for(var i = 1; i < 5; i++){ $('#name').val($scope.accounts.i.name); } The problem: $scope.accounts.i is undefined because i does not count as a varibale inside the $scope variable. It counts as the letter i, so I see no chance to iterate through a scope with a for loop. When I use