Created
September 10, 2012 22:00
-
-
Save ashblue/3694260 to your computer and use it in GitHub Desktop.
Sorts an array by a specific property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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