Skip to content

Instantly share code, notes, and snippets.

@xexi
Created July 31, 2017 08:02
Show Gist options
  • Save xexi/28e447fea2f92ca67f25d397a8bd698d to your computer and use it in GitHub Desktop.
Save xexi/28e447fea2f92ca67f25d397a8bd698d to your computer and use it in GitHub Desktop.
sort by two values prioritizing
var data = [
{ count: '12', year: '1956' },
{ count: '1', year: '1971' },
{ count: '33', year: '1989' },
{ count: '33', year: '1988' }
];
data.sort(function (x, y) { return x.count - y.count || x.year - y.year; });
console.log(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment