James Wayne James Wayne - 19 days ago 5
AngularJS Question

Angular loop through JSON with a limited number

Angular has a built-in feature to loop through JSON, for example I can do:

$scope.users = data.users

But I want to only loop through a number of users to enhance the performance like:

$scope.users = data.users[5] to data.users[10]

How would I be able to do this?

P.S. for pure javascript I can do:

for(var i = 5; i <= 11; i++) {
var user = data.users[i];

Of course this cannot add
to the scope.


You can use the slice method of an array.

$scope.users = data.users.slice(5, 11);