Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort array of objects javascript

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'}
]

books.sort((a, b) => a.name.localeCompare(b.name))
Source by flaviocopes.com #
 
PREVIOUS NEXT
Tagged: #sort #array #objects #javascript
ADD COMMENT
Topic
Name
7+4 =