I'm trying to filter an array of objects using the includes method but I think I'm doing something wrong. Could someone help me?
It doesn't need to be an include method but it must return objects as the example below:
<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>