HomeLanguagesJavascriptCollect.js sortKeysDesc() Method

Collect.js sortKeysDesc() Method

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:

Javascript




const collect = require("collect.js");
  
let obj = {
  name: "Rahul",
  dob: "25-10-96",
  section: "A",
  score: 98,
};
  
const collection = collect(obj);
  
const sorted = collection.sortKeysDesc();
  
console.log(sorted.all());


Output:

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

Example 2:

Javascript




const collect = require("collect.js");
  
let obj = {
  sts_name: "Rakesh",
  id: "1005",
  course: "Web Technology",
  DOB: "15-12-91",
  section: "A",
};
  
const collection = collect(obj);
  
const sorted = collection.sortKeysDesc();
  
console.log(sorted.all());


Output:

{
  sts_name: 'Rakesh',
  section: 'A',
  id: '1005',
  course: 'Web Technology',
  DOB: '15-12-91'
}
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32538 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6920 POSTS0 COMMENTS
Nicole Veronica
12033 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12143 POSTS0 COMMENTS
Shaida Kate Naidoo
7055 POSTS0 COMMENTS
Ted Musemwa
7289 POSTS0 COMMENTS
Thapelo Manthata
7010 POSTS0 COMMENTS
Umr Jansen
6998 POSTS0 COMMENTS