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

标签 javascript angularjs arrays iterator iteration

我有一个数组...

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

我正在使用 ng-repeat 迭代并将每个索引值绑定(bind)到 <p>像这样标记...

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

我如何 ng-bind 数组中除最终索引之外的每个值 "last"值(value)?喜欢...

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

最佳答案

您也可以尝试使用“limitTo”过滤器:

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

关于javascript - Angular : how to iterate through all indices in an array except the final index using ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39175343/

相关文章:

javascript - 定期更新具有相同 URL 的背景图片

c# - 获取元素在 foreach 中引用的内容的名称

javascript - 当它出现在视口(viewport)中时开始 SVG 动画

javascript - 从表单验证

javascript - 单击按钮后AngularJS输出文本框值

arrays - 从 Swift 3 中的字符串数组中读取随机项

java - 能否利用Dijkstra算法找到最快返回路由节点的方法?

javascript - Promise.all 返回函数

javascript - 梅西百货产品 API jQuery

javascript - 在不删除前一个 View 的情况下加载新 View