Collect.js unique() Method Last Updated : 14 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The unique() method is used to return the all of the unique values in the collection. Syntax: collect(array).unique() Parameters: The collect() method takes one argument that is converted into the collection and then unique() method is applied on it. Return Value: This method returns all of the unique items in the collection. Below example illustrate the unique() method in collect.js: Example 1: javascript const collect = require('collect.js'); let arr = [1, 2, 3, 4, 5, 4, 3, 2, 1]; const collection = collect(arr); const unique = collection.unique(); let newObject = unique.all(); console.log(newObject); Output: [1, 2, 3, 4, 5] Example 2: javascript const collect = require('collect.js'); let obj = [ { name: 'Kripamoy', dob: '03-03-98', section: 'A', score: 94, }, { name: 'Biltu', dob: '23-01-96', section: 'B', score: 85, }, { name: 'Santanu', dob: '23-01-98', section: 'B', score: 98, }, { name: 'chinmoy', dob: '18-08-97', section: 'A', score: 72 } ]; const collection = collect(obj); const unique = collection.unique('section'); let newObject = unique.all(); console.log(newObject); Output: [ {name: "Kripamoy", dob: "03-03-98", score: 94, section: "A"}, {name: "Biltu", dob: "23-01-96", score: 85, section: "B"} ] Comment More infoAdvertise with us Next Article Collect.js union() Method C code_hunt Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js union() Method The union() method is used to add the given array to the collection with the unique values. If the given array contains values that are already in the original collection, the original collection's values will be preferred. Syntax: collect.union() Parameters: The collect() method takes one argument 1 min read 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 nth() Method The nth() method is used to create a new collection consisting of every n-th element. Syntax: collect(array).nth(num) Parameters: The collect() method takes one argument that is converted into the collection and then nth() method is applied on it. The nth() method holds a number. Return Value: This 1 min read Collect.js put() Method The put() method is used to set the given key and value in the collection. Syntax: collect(array).put(key) Parameters: The collect() method takes one argument that is converted into the collection and then put() method is applied on it. The put() method holds the key as parameter. Below example illu 1 min read Collect.js only() Method The only() method is used to return the items from the given collection with the specified keys. It takes the key as a parameter and returns the item mapped with that key. Syntax: collect(array).only(key)Parameters: The collect() method takes one argument that is converted into the collection and th 2 min read Collect.js reduce() Method The reduce() method is used to reduce the collection elements into a single value according to the given callback. It works by passing the result of each iteration to the next one resulting in a single value in the end. Syntax: collect(array).reduce(callback) Parameters: The collect() method takes o 1 min read Like