Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created September 10, 2012 22:00
Show Gist options
  • Save ashblue/3694260 to your computer and use it in GitHub Desktop.
Save ashblue/3694260 to your computer and use it in GitHub Desktop.
Sorts an array by a specific property
/**
* Sorts an array by a specific property
* @link https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort
* @example http://jsfiddle.net/truefreestyle/Fqn4J/34/
* @param {array} arrayTarget Array of JSON objects you want to sort
* @param {string} property JSON property you want to sort by
* @returns {undefined}
*/
function arraySort (arrayTarget, property) {
arrayTarget.sort(function (a, b) {
return a[property] - b[property];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment