Reputation: 318
I have defined a separate interface class like this.
export interface FilterCriteria {
continent: number[];
country: number[];
region: number[];
city: number[];
restaurant: number[];
}
In my component i have like this.
values: Filter = {
continent: [],
country: [],
region: [],
city: [],
restaurant: [],
};
And i want to check whether from any of these number arrays this.values.continent, this.values.country, this.values.region, this.values.city, this.valuesrestaurant,
at least 2 number arrays length is greater than 2. How to write a function for that?
Upvotes: 0
Views: 1153
Reputation: 782
First, declare a variable to count how many arrays that are greater than 2. var count = 0;
Then loop through your values and check each arrays length if it's greater than 2 like this if(this.values.continent.length > 2)
.
If the condition is true just add increase the count by 1. count++;
.
When the loop ends you can see how many arrays are there that have lengths more than 2 by accesing count
.
Look at this tutorial about loop in angular
Upvotes: 1