VOOZH about

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

⇱ Collect.js sort() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js sort() Method

Last Updated : 14 Dec, 2020

The sort() method is used to sort the items of the collection.

Syntax:

collect(array).sort()

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

Return Value: This method return the collection after sorting.

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

Example 1:

Output:

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

Example 2:

Output:

[11, 8, 7, 6, 5, 4, 3]
Comment
Article Tags: