我编写了一个产品数组,并使用过滤器方法检查了存在的产品;我想解释一下这行代码(我标记)以及为什么我的代码在不使用if等条件的情况下工作的原因
const Products=[
{
name:'p1',
pExist:0
},{
name:'p2',
pExist:1
},{
name:'p3',
pExist:100
},{
name:'p4',
pExist:0
}
]
const checkExist=function(array){
return array.filter(function(item){
**return item.pExist //<<<==== **here****
})
}
let result=checkExist(Products)
console.log(result)