typescript sort array of objects
const list = [
{ color: 'white', size: 'XXL' },
{ color: 'red', size: 'XL' },
{ color: 'black', size: 'M' }
]
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
typescript sort array of objects
const list = [
{ color: 'white', size: 'XXL' },
{ color: 'red', size: 'XL' },
{ color: 'black', size: 'M' }
]
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us