Skip to content

Instantly share code, notes, and snippets.

@alireza-ahmadi
Created September 22, 2014 14:42
Show Gist options
  • Save alireza-ahmadi/849f8ff49951505faf65 to your computer and use it in GitHub Desktop.
Save alireza-ahmadi/849f8ff49951505faf65 to your computer and use it in GitHub Desktop.
Sort array by specific key
function sortByKey(arr, key) {
function compare(n, m){
return (m.localeCompare(n, 'fa') >= 0)
}
return arr.sort(function(a, b) {
var x,
y;
x = a[key];
y = b[key];
return ((check(x, y)) ? -1 : ((check(y, x)) ? 1 : 0));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment