Skip to content

Instantly share code, notes, and snippets.

@DiogenisPanagiotis
Created February 21, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiogenisPanagiotis/24616f729dbd25f8b5300de3a3dce239 to your computer and use it in GitHub Desktop.
Save DiogenisPanagiotis/24616f729dbd25f8b5300de3a3dce239 to your computer and use it in GitHub Desktop.
Hotjar JavaScript Function To Order Object By Age
// 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