Backbone.JS Sort()

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

Syntax:

Collection.Sort (options)

Parameters: options: This parameter is used to specify either of the two values: “true” or “false”. True enables the sorting while false disables it.

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 Sort() method maintains the collection in sorted order based on the value of the ‘id’.

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