I encountered a small problem, that I can't figure out or find a solution to, on the internet, at least that I'm aware of. I want to filter an object in javascript, based on a undefined number of values in an array. I have an object like this:
categories = { "category1: {"_id": "1234"}, "category2: {"_id": "4567"}, ... };
I also have an array including values of IDs, like so:
catArray = ["1234", "4567", ... ]
Now I want to filter all categories out of the category-Object, matching the IDs from the array. I managed to filter the category for a single array-value, but not for all. It's working like this:
const categoriesFilter = categories.filter(cat => {
return cat._id == catArray[0];
});
So far it is working. But now I want to match the categories from all possible ID-values from the array. I tried to do it with a for-loop, but it's not working out. Any idea? Thanks a lot in advance.
categorieswas a plain object. Those don’t havefilter. Iscategoriesactually an array?_iddoesn't match the data either which hasid.