Created
February 21, 2017 17:15
-
-
Save DiogenisPanagiotis/24616f729dbd25f8b5300de3a3dce239 to your computer and use it in GitHub Desktop.
Hotjar JavaScript Function To Order Object By Age
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
// Make sameple object | |
var hotjarObj = [{ | |
name: 'David', | |
age: 23 | |
}, | |
{ | |
name: 'Sara', | |
age: 25 | |
}, | |
{ | |
name: 'Patrick', | |
age: 27 | |
}]; | |
// Sort the hotjarObj by age using inline ternary operator | |
hotjarObj.sort((a, b) => { return (a.age > b.age) ? 1 : ((b.age > a.age) ? -1 : 0); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment