This is probably a silly question, but how can I sort the below given array based on Values of it's Objects (Ascending Order - 1 to 6).
I can't use Object Key as an identifier since it's dynamic and will change based on User's settings. I got it working using the commented solution, but it doesn't work in IE since IE doesn't support "Object.values" yet.
$scope.data = [
{ Type: 6 },
{ Path: 1 },
{ Text: 2 },
{ Name: 3 },
{ Icon: 5 },
{ Case: 4 }
];
$scope.data.sort(function (a, b) {
// This commented solution works fine in Chrome and FF, but not in IE since IE doesn't support "Object.values" yet.
//if (Object.values(a) < Object.values(b))
// return -1;
//if (Object.values(a) > Object.values(b))
// return 1;
//return 0;
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
});
// Desired Result
$scope.data = [
{ Path: 1 },
{ Text: 2 },
{ Name: 3 },
{ Case: 4 },
{ Icon: 5 },
{ Type: 6 }
];