VOOZH about

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

⇱ Collect.js sortKeysDesc() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js sortKeysDesc() Method

Last Updated : 9 Dec, 2020

The sortKeysDesc() method is used to sort the collection elements in descending order by the given keys of the underlying associative array.

Syntax:

collect(array).sortKeysDesc(key)

Parameters: The collect() method takes one argument that is converted into the collection and then sortKeysDesc() method is applied to it. The sortKeysDesc() method holds the key as a parameter.

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

Below example illustrate the sortKeysDesc() method in collect.js:

Example 1:

Output:

{ section: 'A', score: 98, name: 'Rahul', dob: '25-10-96' }

Example 2:

Output:

{
 sts_name: 'Rakesh',
 section: 'A',
 id: '1005',
 course: 'Web Technology',
 DOB: '15-12-91'
}
Comment
Article Tags: