James Wayne James Wayne - 1 year ago 86
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.

Answer Source

You can use the slice method of an array.

$scope.users = data.users.slice(5, 11);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download