I want to add conditions in JavaScript filter() method dynamically.
I have the code below:
let condition = ''; let a = ['empEmail', 'employeeAction', 'transactionNo', 'deviceListName', 'projectName']; if (this.selectedEmployeeAlias != undefined) { condition += '&& a => a.empEmail === this.selectedEmployeeAlias'; } if (this.employeeStatusList != undefined) { condition += '&& a.employeeAction === this.employeeStatusList' } if (this.selectedTransactionNo != undefined) { condition += '&& a.transactionNo === this.selectedTransactionNo'; } if (this.selectedDeviceList != undefined) { condition += ' && a.deviceListName == this.selectedDeviceList'; } if (this.selectedProjectName != undefined) { condition += '&& a.projectName == this.selectedProjectName'; } var finalCondition = condition.substring(2, condition.length); var fArray = arrayDetails.filter(finalCondition); The code is returning an error as:
finalConditionis not a function.
Could you please let me know how can I add conditions to filter() dynamically.
thisis pointing to.