Skip to content

Instantly share code, notes, and snippets.

@lauris
Created July 19, 2016 11:11
Show Gist options
  • Save lauris/408e5ff4b16250fcc6b605e2a1f361f7 to your computer and use it in GitHub Desktop.
Save lauris/408e5ff4b16250fcc6b605e2a1f361f7 to your computer and use it in GitHub Desktop.
var data = [
{name: "John", age: 28},
{name: "Jane", age: 25}
];
function orderByKey(data, key) {
var comparator = function (a,b) {
return parseInt(a[key]) - parseInt(b[key]);
};
return data.sort(comparator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment