Erik Ásland Erik Ásland - 3 months ago 13
AngularJS Question

Angular: how to iterate through all indices in an array except the final index using ng-repeat

I have an array...

$scope.arr = ["first", "second", true];


I am using ng-repeat iterate through and bind each index value to a
<p>
tag like so...


<div ng-repeat="value in arr">
<p ng-bind="value"></p>
</div>


How do I ng-bind every value in the array except the final index
"last"
value? Like...


<div>
<p>first</p>
</div>
<div>
<p>second</p>
</div>

Answer

You can also try using the "limitTo" filter:

<div ng-repeat="value in arr | limitTo : arr.length-1">
    <p ng-bind="value"></p>
</div>