我正在尝试使用该方法过滤对象数组includes,但我认为我做错了。有人可以帮助我吗?它不需要是一个包含方法,但它必须返回对象,如下例所示:
<html>
<script>
const testeArray = [{name:"antonio", category: ["One","Two"]},{name:"joana", category: ["Two"]}];
const catArray1 = ["One","Two"];
const catArray2 = ["One"];
const text = "an"
const resultArray1 = testeArray.filter((item)=>{
return item.name.includes(text) && item.category.includes(catArray1);
})
console.log(resultArray1); //should return antonio and joana objects
const resultArray2 = testeArray.filter((item)=>{
return item.name.includes(text) && item.category.includes(catArray2);
})
console.log(resultArray2); //should return antonio object only
</script>
</html>
<html>
<script>
const testeArray = [{name:"antonio", category: ["One","Two"]},{name:"joana", category: ["Two"]}];
const catArray1 = ["One","Two"];
const catArray2 = ["One"];
const text = "an"
const resultArray1 = testeArray.filter((item)=>{
return item.name.includes(text) && item.category.includes(catArray1);
})
console.log(resultArray1); //should return antonio and joana objects
const resultArray2 = testeArray.filter((item)=>{
return item.name.includes(text) && item.category.includes(catArray2);
})
console.log(resultArray2); //should return antonio object only
</script>
</html>
偶然的你
MMTTMM
aluckdog
相关分类