Collect.js mode() Method Last Updated : 27 Nov, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The mode() method of collect.js is used to return the mode of the given key. The mode is the value that occurs most frequently in a set of observations. Syntax: collect(array).mode(key) Parameters: The collect() method takes one argument that is converted into the collection and then mode() method is applied to it. The mode() method holds the key as a parameter. Return Value: This method returns the mode of the given key from the collection. Below example illustrate the mode() method in collect.js: Example 1: JavaScript const collect = require('collect.js'); let arr = [1, 1, 3, 3, 3, 5, 5, 6]; const collection = collect(arr); const mode_val = collection.mode(); console.log(mode_val); Output: 3 Example 2: JavaScript const collect = require('collect.js'); let obj = [ { name: 'Rahul', dob: '25-10-96', section: 'A', score: 98, }, { name: 'Aditya', dob: '25-10-96', section: 'B', score: 96, }, { name: 'Abhishek', dob: '16-08-94', section: 'A', score: 98 } ]; const collection = collect(obj); const mode_val = collection.mode('score'); console.log(mode_val); Output: 98 Comment More infoAdvertise with us Next Article Collect.js pop() Method A ashokjaiswal Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js times() Method The times() method is used to create a new collection by invoking the callback a given amount of times. Syntax: collect.times() Parameters: The collect() method takes one argument that is converted into the collection and then times() method is applied on it. Return Value: This method returns a new 1 min read Collect.js sum() Method The sum() method in collect.js is used to return the sum of all the items in the given collection. Syntax: collect(array).sum() Parameters: The collect() method takes one argument that is converted into the collection and then sum() method is applied on it. Return Value: This method returns the sum 1 min read Collect.js pop() Method The pop() method is used to remove the last element from collection and returns the popped element. Syntax: collect(array).pop() Parameters: The collect() method takes one argument that is converted into the collection and then pop() method is applied on it. Return Value: This method returns the pop 1 min read Collect.js min() Method The min() method is used to return the minimum element from the given array or collection. The method can be specified with a key as a parameter so that only the values of that key in the collection would be considered and the minimum element would be found from those values. Syntax: collect(array). 1 min read Collect.js pad() Method The pad() method is used to fill the array with the given element until the size of the array is full. We use a negative size to pad the elements left side and use a positive sign to pad elements right side. If the array size is full then no padding will perform. Syntax: collect(array).pad(size, val 2 min read Collect.js sortDesc() Method 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 colle 1 min read Like