Answers for "Sorting an array of objects on both ascending and descending order on same click"

0

Sorting an array of objects on both ascending and descending order on same click

self.isAscending = true;

self.sortTitle = function () {
 if(self.isAscending){ 
   self.arr= self.arr.sort((a, b) => (a.title > b.title) ? 1 : -1);
 }else{
   self.arr= self.arr.sort((a, b) => (a.title > b.title) ? -1 : 1);
 }
 self.isAscending = !self.isAscending;
}
Posted by: Guest on August-18-2021

Code answers related to "Sorting an array of objects on both ascending and descending order on same click"

Code answers related to "Javascript"

Browse Popular Code Answers by Language