I have an array of objects. Each object has a Name, Surname, Phone, PostCode etc. My aim is to sort this array by passing criteria (sort either ASC or DESC).
filterBy(criteria) {
this.items.sort(by_criteria)
}
So when I pass "Name" as a criteria, it will sort it by Name etc.
I cannot find the way to apply on each spesific element of the object. How could I say for exaple:
1)(click)=filterBy("name");
2) filterBy(criteria) {
this.items.sort(this.items.criteria)
}
What is the most elegant/easy/right way to do that?
Thank you!