const cars = [
{
brand: "Chevrolet",
model: "Camaro",
dates: (3) ['2022/05/28', '2022/06/02', '2022/06/05']
},
{
brand: "Chevrolet",
model: "Camaro",
dates: (3) ['2022/05/30', '2022/06/02', '2022/06/05']
},
{
brand: "Chevrolet",
model: "Camaro",
dates: (3) ['2022/05/28', '2022/06/01', '2022/06/05']
}
]
I want to filter my object array based on another array
const arr2 = ["2022/06/02", "2022/06/05"];
I want to get results like that;
[
{
brand: "Chevrolet",
model: "Camaro",
dates: (3) ['2022/05/28', '2022/06/02', '2022/06/05']
},
{
brand: "Chevrolet",
model: "Camaro",
dates: (3) ['2022/05/30', '2022/06/02', '2022/06/05']
}
]
I used includes
let filtered = cars.filter((item) => item.dates.includes(arr2))
I got empty array.
when I pass a string to in includes I got filtered array.
let filtered = cars.filter((item) => item.dates.includes("2022/06/02"))
No I need to compare arr2. Its' length could be changed.
How can I pass an array to cars.include()
function