I have two arrays, one store the conditions and other array contain data objects. I am looking for a way to iterate through the condition array and if anyone match found, then add them to the result. Below is the function, that I wrote to do this but with always with only one condition i.e. searchableColumns[0]
private _filter(value: any): string[] {
const filterValue = value.toLocaleLowerCase();
var result = this.searchData.filter(option => option[this.searchableColumns[0]].toLocaleLowerCase().includes(filterValue));
return result;
}
But I want to check for other searchableColumns as well. These matching is an OR condition. Also When adding to the result, I want to concatenate the object's property as string.
For, example, say I have
this.searchData = [{key: "1", name: "One", value: "Once"}, {key: "2", name: "Two", value:"On Twice"}, {key: "3", name: "Three", value: "Thrice"}];
and
this.searchableColumns = ["name", "value"];
and when the function is called with parameter On, then the result will be
result = ["1|One|Once", "2|Two|On Twice"]
as result[0] has name with "On" and result[1] contains value with "On".
Please let me know, if it can be done and can be improvised. Thank you for your time.