Backbone.JS Comparator()

The Backbone.JS Comparator() collection method is used to sort the items in the collection.

Syntax:

Collection.Comparator 

Example:

  

  
Example  
  
  
  
  
  
  
  
  

Output:

Sorted based on id: [{"id":2,"name":"Jim"},{"id":10,"name":"Tom"},{"id":33,"name":"Kim"}]

Explanation: In the above example, the Comparator() method maintains the collection in sorted order based on the value of the ‘id’.

Please follow and like us:
Content Protection by DMCA.com