var data = [{ TagId: 1, TagName: "C#", },
{ TagId: 2, TagName: "Single Page Application", },
{ TagId: 3, TagName: "Visual Studio", },
{ TagId: 4, TagName: "Fakes", }]
var posts = [];
posts = sortByKeyDesc(data, "TagId");
function sortByKeyDesc(array, key) {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
}
function sortByKeyAsc(array, key) {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
{ TagId: 2, TagName: "Single Page Application", },
{ TagId: 3, TagName: "Visual Studio", },
{ TagId: 4, TagName: "Fakes", }]
var posts = [];
posts = sortByKeyDesc(data, "TagId");
function sortByKeyDesc(array, key) {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
}
function sortByKeyAsc(array, key) {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}