I've been attempting to filter an array with multiple filters, but I can't seem to achieve the desired outcome so far.
This is my Angular component:
list = [ {type: type1, code: code1}, {type: type2, code: code2}]
searchElement(code?: string, type?: string){
var myVar = this.list
if(type)
myVar = myVar.filter(elt => elt.type.indexOf(type) > -1);
if(code)
myVar = myVar.filter(elt => elt.type.indexOf(code) > -1);
//call another function myFunction() with the filtered array myVar
}
Due to its asynchronous behavior, myFunction()
is being called before myVar is properly filtered. How can I ensure that myVar is fully filtered before calling myFunction()
?