【发布时间】:2014-09-15 20:09:03
【问题描述】:
我正在使用$.each() 解析一个数组,但在其中,我使用的是.splice() 方法,所以我需要向后迭代。有可能吗?
var store = [...];
//...
var rules = [...];
//...
$.each(store, function(index, element) { // This loop needs to iterate backward
$.each(rules, function(index2, rule) {
if (element.id == rule.id) {
store.splice(index, 1);
}
});
});
警告:
- 我不想反转数组,它不会是相同的行为。
- 我也知道我可以使用
for,我只是想知道使用$.each是否可以实现
【问题讨论】:
-
不,我看过这篇文章,它在阵列上使用
.reverse()。请完整阅读问题。 -
查看这篇文章:stackoverflow.com/questions/9882284/… 要正确使用
.splice,您必须向后迭代。而$.each()基本上不是。 -
为什么可以使用简单的
for循环? -
我可以像我在问题中写的那样。我终于做到了。^^ 但我想知道使用
$.each()是否可行。