我有一个对象,包含 5 个元素。
现在我循环删除与我的条件匹配的元素。
for(var i = 0; i < items.length ; i++){
console.log(i + '-'); //the result is 3-4
if(_today.getTime() - items[i].timestamp >= numDay * ONE_DAY){
console.log(i); //the result is 3
items.splice(i,1);
}
}
我的数组样本:
[{"DepartmentID":56,"CategoryID":117,"BrandID":19,"ID":707},
{"DepartmentID":56,"CategoryID":117,"BrandID":19,"ID":708},
{"DepartmentID":56,"CategoryID":117,"BrandID":19,"ID":709},
{"DepartmentID":56,"CategoryID":117,"BrandID":19,"ID":710},
{"DepartmentID":56,"CategoryID":117,"BrandID":19,"ID":711}]
只删除 this 中的一个元素for loop
。是因为问题的索引吗?如何删除n
与此循环中的条件匹配的元素?
任何帮助将不胜感激,谢谢..