In my angualar project I have a table with a list of users and the search bar. Here is my search function:
searchUser() {
const regExp = new RegExp(this.searchTerm, 'gi');
this.users = this.users.filter((user) => regExp.test(user.username));
}
Now its searching only by username, but I want to be able to search by selected field. I have a select with options of my search criterion. So I dont know how dynamicly change property of user object inside filter fuction in according to selected search criterion.
I've thought about es6 template strings and tried like this:
this.users = this.users.filter((user) => regExp.test(user`.${this.selectedCriterion}`)
But it didn't work. What is the proper syntax for this? Will appreciate any advise