Collect.js diff() Function Last Updated : 15 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The diff() function compares the main collection against the given collection and returns the values that are in the original collection but not in the given collection. Syntax: data.diff(collection)Parameters: This function accepts a single parameter as mentioned above and described below:collection: Hold the collection that will be compared with the main collection.Return Value:Returns a new collection with difference between collection items.Example 1: Here in this example, we take a collection and then using the diff() function and return the value not in the new collection. JavaScript // It is used to import collect.js library const collect = require('collect.js'); const collection = collect([1, 2, 3, 4, 5 ,6]); console.log(collection.diff([1, 2, 5])); Output:Collection { items: [ 3, 4, 6 ] }Example 2: There is one thing to notice that this function holds a collection, compare with the main collection but only return only those items that are extra in the main collection. JavaScript // It is used to import collect.js library const collect = require('collect.js'); const col1 = [1, 2, 3, 4]; const col2 = [3, 4, 5, 6]; const x = collect(col1); const y = collect(col2); const difference = x.diff(y); console.log(difference.all()); Output:[ 1 , 2] Comment More infoAdvertise with us Next Article Collect.js | forPage() Function A akhilsharma870 Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js diffKeys() Function Collect.js is a library in Javascript, which acts as a wrapper for arrays and objects. This library used to convert the array and objects into collections and then perform different operations on them. The diffKeys method of collect.js converts the array into collections and then compares the collec 1 min read Collect.js first() Function The first() function gives the first value of the collection. It returns the first value or the first method returns the first element in the collection that passes a given condition. Syntax: data.first(e)Parameters: This function accepts a single parameter as mentioned above and described below:e: 1 min read Collect.js | forPage() Function The forPage() function is used to return the value which is present at a particular page, this function take the page number as an argument and then returns the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax:Â data.f 1 min read Collect.js count() Function The count() function is used to count the number of collections in the element. Syntax: data.count()Parameters: This function does not accept any parameterReturn Value:Returns the count of the element in that collection.Example 1:Below examples illustrate the count() function in collect.js JavaScrip 1 min read Collect.js | zip() Function The zip() function is used to combine the values of given array with the values of original collection at a given index. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax:Â data.zip(value) Parameters:Â This function accept a single 2 min read Collect.js | get() Function The get() function is used to return a value that is present at a particular key. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.get('key') Parameters: This function accept a single parameter as mentioned above and describ 1 min read Like