I can not loop throught object in react with typescript. I am using redux toolkit and I want to get chosenFilters arrays.
const chosenFilters = useSelector((state: RootState) => state.recipe.filters);
for (const chosenFilterArray of chosenFilters) {
console.log(chosenFilterArray);
}
error:
Type 'filters' is not an array type or a string type.
interface:
export interface filters {
filterTypes: string[];
filterLengths: string[];
}
filtersisn't an array. It's an object with two properties which are arrays. Are you trying to loop over one or both of those properties? Loop over the properties of the object? Something else?