const books = [
{id: 1, name: 'The Lord of the Rings'},
{id: 2, name: 'A Tale of Two Cities'},
{id: 3, name: 'Don Quixote'},
{id: 4, name: 'The Hobbit'}
]
// the 1 and -1 can be switched for standard sort
books.sort((a,b) => (a.id > b.id) ? -1 : ((b.id > a.id) ? 1 : 0));
// Code idea from fancyfinch