Skip to main content
added 36 characters in body
Source Link
sfdcfox
  • 501.8k
  • 21
  • 473
  • 828

You can do this with Array.every:

let filters = [];
this.regionFilterValue &&
  filters.push((row) => row.Region__c === this.regionFilterValue);
this.filterVBundle &&
  filters.push((row) => row.vertical_bundle__c === this.filterVBundle);
this.filterAccountSizeValue &&
  filters.push((row) => row.EO_Account_Size__c === this.filterAccountSizeValue);
this.filteredList = this.constList.filter((row) =>
  filters.every((filter) => filter.call(this, row)) 
);

Every returns true if all values are true, otherwise false. We use arrow functions for brevity, and we can use value && method to apply the right-hand-side only if the left-hand-side is truthy (i.e. not zero, null, empty string, or undefined).

You can do this with Array.every:

let filters = [];
this.regionFilterValue && filters.push((row) => row.Region__c === this.regionFilterValue);
this.filterVBundle && filters.push((row) => row.vertical_bundle__c === this.filterVBundle);
this.filterAccountSizeValue && filters.push((row) => row.EO_Account_Size__c === this.filterAccountSizeValue);
this.filteredList = this.constList.filter((row) => filters.every((filter) => filter.call(this, row)));

Every returns true if all values are true, otherwise false. We use arrow functions for brevity, and we can use value && method to apply the right-hand-side only if the left-hand-side is truthy (i.e. not zero, null, empty string, or undefined).

You can do this with Array.every:

let filters = [];
this.regionFilterValue &&
  filters.push((row) => row.Region__c === this.regionFilterValue);
this.filterVBundle &&
  filters.push((row) => row.vertical_bundle__c === this.filterVBundle);
this.filterAccountSizeValue &&
  filters.push((row) => row.EO_Account_Size__c === this.filterAccountSizeValue);
this.filteredList = this.constList.filter((row) =>
  filters.every((filter) => filter.call(this, row)) 
);

Every returns true if all values are true, otherwise false. We use arrow functions for brevity, and we can use value && method to apply the right-hand-side only if the left-hand-side is truthy (i.e. not zero, null, empty string, or undefined).

Source Link
sfdcfox
  • 501.8k
  • 21
  • 473
  • 828

You can do this with Array.every:

let filters = [];
this.regionFilterValue && filters.push((row) => row.Region__c === this.regionFilterValue);
this.filterVBundle && filters.push((row) => row.vertical_bundle__c === this.filterVBundle);
this.filterAccountSizeValue && filters.push((row) => row.EO_Account_Size__c === this.filterAccountSizeValue);
this.filteredList = this.constList.filter((row) => filters.every((filter) => filter.call(this, row)));

Every returns true if all values are true, otherwise false. We use arrow functions for brevity, and we can use value && method to apply the right-hand-side only if the left-hand-side is truthy (i.e. not zero, null, empty string, or undefined).