【发布时间】:2017-05-30 13:26:27
【问题描述】:
我有一个 [2016,2017,2018,2019] 数组
我有一个从Value 2017到Value 2017的范围
因此结果数组应该是 [2017] 因为我需要删除 fromValue 和 toValue 之间超出范围的任何内容。
我在下面编写的代码只删除了 2016 年和 2018 年,而不是 2019 年。
我在做什么错了,有没有更好的方法来做到这一点?
gNodeIDs.forEach(function (item) {
alert("Before if" + item);
if (item >= fromValue) {
if (item <= toValue) {
}
else
{
alert("removing" + item);
var index = test.indexOf(item);
if (index >= 0) {
test.splice(index, 1);
}
}
}
else {
alert("removing" + item);
var index = test.indexOf(item);
if (index >= 0) {
test.splice(index, 1);
}
}
});
【问题讨论】:
-
怎么样?使用过滤器?
标签: javascript jquery arrays scripting logic