VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-sortdesc-method/

⇱ Collect.js sortDesc() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js sortDesc() Method

Last Updated : 6 Aug, 2021

The sortDesc() method is used to sort the collection in the opposite order as the sort method.

Syntax:

collect.sortDesc()

Parameters: The collect() method takes one argument that is converted into the collection and then sortDesc() method is applied on it.

Return Value: This method returns the collection in descending order.

The below example illustrates the sortDesc() method in collect.js:

Example 1:

Output:

[11, 8, 7, 6, 5, 4, 3]

Example 2:

Output:

 [ 
 { 
 subject: 'science', 
 score: 90, 
 },
 { 
 subject: 'English', 
 score: 95, 
 },
 { 
 subject: 'math', 
 score: 86, 
 }
]
Comment
Article Tags: