在任何人打电话之前,请先通读一遍。。。
我试着在多种情况下使用过滤函数,但似乎不起作用,很多解决方案粗略地说我可以做到。。。
const data = [
{CatalogID: -1, SectionID: 0},
{CatalogID: 2, SectionID: 9},
{CatalogID: 2, SectionID: 9},
{CatalogID: -1, SectionID: 0},
{CatalogID: -1, SectionID: 0},
{CatalogID: 3, SectionID: 6},
{CatalogID: 3, SectionID: 6},
{CatalogID: -1, SectionID: 0},
{CatalogID: 3, SectionID: 6}
]
data.filter(f=>f.SectionID == 6 && f.SectionID == 0 && f.CatalogID == -1)
let a = data.filter(function(e) {
return e.SectionID == 6 && e.SectionID == 0 && e.CatalogID == -1
});
console.log(a);
但这些都是空的。。。但是当我在数据对象中循环时,就像这样。。。
let holder = [];
for(let i = 0; i < data.length; i++){
if(data[i].SectionID === 6 || data[i].SectionID === 0 || data[i].CatalogID === -1) holder.push(data[i]);
}
console.log(holder);
holder = [];
然后它完成了任务,但并不漂亮。
**编辑**
我想要的结果是。。。
{CatalogID: -1, SectionID: 0},
{CatalogID: -1, SectionID: 0},
{CatalogID: -1, SectionID: 0},
{CatalogID: 3, SectionID: 6},
{CatalogID: 3, SectionID: 6},
{CatalogID: -1, SectionID: 0},
{CatalogID: 3, SectionID: 6}