I have an array of items items[]
. Each one has a boolean property filtered
and a property that is an array called tags[]
.
I also have another array: selected_tags
.
With this loop, I can filter all items based on the selected tags:
items.forEach(function (item) {
if (selected_tags.length > 0)
tag_filter = !selected_tags.some(tag => item.tags.includes(tag));
// ... other_filter = something else...
item.filtered = !(!tag_filter && !other_filter);
});
This works with a ANY logic (if any tag is in the selected ones, show the item). I'd like to do this with an ALL logic (if all the selected tags are in the item tags, then show it).
So, naturally, I was wondering if includes can do something like this:
[1,2,3].includes([1,2,3])
[1,2,3].includes(1,2,3)
tag_filter = item.tags.includes(selected_tags);
But it gives false.
Can I do this while keeping it as a simple one liner that returns tag_filter = true
if filtered and false
if not?