Open In App

Collect.js Complete Reference

Improve
Improve
Like Article
Like
Save
Share
Report

Collect.js is the JavaScript library for collecting data from tree-based structures. It is a fluent and convenient wrapper for working with arrays and objects. It provides us with different functions that help in working with data much easier. It also helps the programmers to write more concise code and easier to maintain the JavaScript code.

Methods

Description

Collect.js all() Method

The all() method is used to return the underlying array or object represented by the collection.

Collect.js average() Method

The average() method is used to return the average of all the items in a collection

Collect.js avg() Method

The avg() method returns the average of all the items in a collection.

Collect.js chunk() Method

The chunk() function breaks the collection into many small collections of the given size

Collect.js collapse() Method

The Collapse() method converts a collection of arrays into a single flat array.

Collect.js combine() Method

The Combine() Method combines two different arrays with keys-values. The first array contains keys combined with the second array Which contains values.

Collect.js concat() Method

The concat() method is used to return the merged arrays or objects represented by the collection.

Collect.js contains() Method

The contains() method is used to determine whether the collection contains a given item or not.

Collect.js count() Method

The count() Method is used to count the number of collections in the element.

Collect.js countBy() Method

The countBy() Method is used to count the occurrence of values in the collection. This method counts the occurrence of every element.

Collect.js crossJoin() Method

The crossJoin() Method used to cross joins the collection with an array or collection and return all possible permutations between them.

Collect.js dd() Method

The dd() Method in collect.js is used to log the output of the function and stop the further execution thus exiting the current process.

Collect.js diff() Method

The diff() Method compares the main collection against the given collection and returns the values which are in original collection but not in the given collection.

Collect.js diffAssoc() Method

The diffAssoc() Method is used to compare two given collection and returns the values and their indices which are not present in the given collection.

Collect.js diffKeys() Method

The diffKeys() Method converts the array into collections and then compares the collection against another collection based on its keys and returns elements in the original collection that are not present in another collection.

Collect.js dump() Method

The dump() Method in collect.js is used to print the data at particular moment and then continue further executing the code.

Collect.js duplicates() Method

The duplicates() Method is used to extract the duplicates from the given array. It returns an object containing key as the index of the duplicate and value as the duplicate itself.

Collect.js each() Method

The each() Method iterates over the items in the collection and passes each item to a callback.

Collect.js eachSpread() Method

The eachSpread() Method is used to iterate over the collection items and pass each nested item value of collection into the given callback function

Collect.js every() Method

The every() Method is used to verify all elements of the given collection and use a given truth test.

Collect.js except() Method

The except() Method is used to return all items in the given collection except the specified keys

Collect.js filter() Method

The filter() Method is used to filter the given collection using the given callback function and returns the collection element.

Collect.js first() Method

Simply means it returns the first value or the first method returns the first element in the collection that passes a given condition.

Collect.js firstWhere() Method

The firstWhere() method is used to return the first element from a collection with the given key and value pair. It can be used to find any element in an array by only specifying any of the key-value pairs in an object.

Collect.js flatMap() Method

The flatMap() method is used to iterate all the collection elements and pass each collection elements into given callback.

Collect.js flatten() Method

The flatten() method is used to flatten a multi-dimensional collection into a single dimensional collection and returns the flatten single dimensional collection elements.

Collect.js flip() Method

The flip() Method swaps the key with its corresponding value.

Collect.js forPage() Method

The forPage() Method 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.

Collect.js forget() Method

The forget() Method as the name suggest forgets/remove an item from the collection using its key.

Collect.js get() Method

The get() Method is used to return a value that is present at a particular key.

Collect.js groupBy() Method

The groupBy() method is used to group the given collection items into multiple collections by a given key

Collect.js has() Method

The has() method in Collect.js is used to check whether the key exists in the collection or not.

Collect.js implode() Method

The implode() method is used to join the given items into the collection.

Collect.js intersect() Method

The intersect() function is used to remove the value in the main collection which is not present

Collect.js intersectByKeys() Method

The intersectByKeys() method is used to remove any given keys from the original collection that are not present in the given array or collection

Collect.js isEmpty() Method

The isEmpty() method is used to check the given collection is empty or not and returns the corresponding boolean value.

Collect.js isNotEmpty() Method

The isNotEmpty() method is used to check the given collection is not empty or empty and returns the corresponding boolean value.

Collect.js join() Method

The join() method is used to join the collection elements with given string and returns the collection elements.

Collect.js keyBy() Method

The keyBy() method is used to keys the collection elements by the given key. If the collection contains multiple items with same key then the last element will appear.

Collect.js keys() Method

The keys() method is used to return all of the collection’s keys.

Collect.js last() Method

The last() method is used to return the last element from the collection that satisfy the given truth test.

Collect.js macro() Method

The macro() method is used to register a custom method. This method used the custom function.

Collect.js make() Method

Collect.js is a fluent and convenient wrapper for working with arrays and objects. The make() function creates a new collection instance.

Collect.js map() Method

The map() function iterates through a collection and pass each value to callback.

Collect.js mapInto() Method

The mapInto() method is used to iterate through the collection elements and instantiate the given class with each element as a constructor.

Collect.js mapSpread() Method

The mapSpread() method is used to iterate over the given collection items and pass each nested collection item value into the given callback.

Collect.js mapToDictionary() Method

The mapToDictionary() method is used to run a dictionary map over the collection items.

Collect.js mapToGroups() Method

The mapToGroups() method is used to iterate through the collection elements and passes each value of collection into the given callback function.

Collect.js mapWithKeys() Method

The mapWithKeys() method is used to iterate through the collection elements and passes each collection element into the given callback function.

Collect.js max() Method

The max() method is used to return the maximum value of a given key.

Collect.js median() Method

The median() method is used to return the median of the collection elements or median of the given key from the collection.

Collect.js merge() Method

The merge() method is used to merge the given object into the original collection.

Collect.js mergeRecursive() Method

The mergeRecursive() method is used to merge the given array or collection elements recursively with the original collection.

Collect.js min() Method

The min() method is used to return the minimum element from the given array or collection.

Collect.js mode() Method

The mode() method of collect.js is used to return the mode of the given key.

Collect.js nth() Method

The nth() method is used to create a new collection consisting of every n-th element.

Collect.js only() Method

The only() method is used to return the items from the given collection with the specified keys.

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.

Collect.js partition() Method

The partition() method is used to separate the collection elements according to the given callback function.

Collect.js pipe() Method

The pipe() method is used to hold a callback function and apply this function into the collection and returns the corresponding result.

Collect.js pluck() Method

The pluck() method is used to return all the values from the given key.

Collect.js pop() Method

The pop() method is used to remove the last element from collection and returns the popped element.

Collect.js prepend() Method

The prepend() method is used to add an item at the beginning of the given collection.

Collect.js pull() Method

The pull() method is used to remove an element from collection by given key and return the pulled element.

Collect.js push() Method

The push() function is used to add a new value to the end of the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection

Collect.js put() Method

The put() method is used to set the given key and value in the collection.

Collect.js random() Method

The random() function as the name suggest it returns any random value from the collection.

Collect.js reduce() Method

The reduce() method is used to reduce the collection elements into a single value according to the given callback.

Collect.js reject() Method

The reject() method is used to filter the given collection of elements using the given callback function.

Collect.js replace() Method

The replace() method is used to replace the elements of the original collection that match the given string or numeric keys.

Collect.js replaceRecursive() Method

The replaceRecursive() method is similar to the replace() method but it works recursively and this method will recurse into arrays and the inner values are treated with the same replacement process.

Collect.js reverse() Method

The reverse() method is used to reverse the order of the given collection. It can be used to reverse an array of elements or nested objects.

Collect.js search() Method

The search() method is used to search the given element in collection and returns its key if it exists. If the element is not found then it returns false.

Collect.js shift() Method

The shift() method is used to remove the first element from collection and returns it.

Collect.js shuffle() Method

The shuffle() method is used to return the collection elements randomly.

Collect.js skip() Method

The skip() method is used to skip the given number of elements from collection and returns the remaining collection elements.

Collect.js skipUntil() Method

The skipUntil() method is used to skip the collection elements until the given callback returns true and then returns the remaining items in the collection:

Collect.js skipWhile() Method

The skipWhile() method is used to skip the collection elements while the given callback function returns true and returns the remaining collection elements.

Collect.js slice() Method

The slice() method is used to return a slice of the given collection starting at given index.

Collect.js some() Method

The some() method is used to check whether the given collection contains a given item or not and returns the corresponding boolean value.

Collect.js sort() Method

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

Collect.js sortBy() Method

The sortBy() method is used to sort the collection by the given key.

Collect.js sortByDesc() Method

The sortByDesc() method is used to sort the given collection elements into descending order according to given key.

Collect.js sortDesc() Method

The sortDesc() method is used to sort the collection in the opposite order as the sort method.

Collect.js sortKeys() Method

The sortKeys() method is used to sort the collection elements by the given keys of the underlying associative array.

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.

Collect.js splice() Method

The splice() method is used to remove and returns a slice of items starting at the specified index

Collect.js split() Method

The split() method in collect.js is used to break a collection into the given number of groups.

Collect.js sum() Method

The sum() method in collect.js is used to return the sum of all the items in the given collection.

Collect.js take() Method

The take() method is used to return a new collection with the specified number of items.

Collect.js takeUntil() Method

The takeUntil() method is used to return the items in the collection until the given callback returns true.

Collect.js takeWhile() Method

The takeWhile() method is used to return the items in the collection until the given callback returns false.

Collect.js tap() Method

The tap() Method accepts the collection as a parameter and without affecting the collection it allows the user to tap into the collection at a specific point and do anything with the item.

Collect.js times() Method

The times() method is used to create a new collection by invoking the callback a given amount of times.

Collect.js toArray() Method

The toArray() method is used to convert the given collection into a normal array. An array containing the values will be returned if the collection is an object.

Collect.js toJson() Method

The toJson() method is used to convert the collection into a JSON string.

Collect.js transform() Method

The transform() Method iterates over a collection and callback each item in the collection, the items inside the collection are replaced by the new callback values.

Collect.js union() Method

The union() method is used to add the given array to the collection with the unique values.

Collect.js unique() Method

The unique() method is used to return the all of the unique values in the collection.

Collect.js unless() Method

The unless() method is executes the callback provided when false is evaluated by the first argument given to the method.

Collect.js unlessEmpty() Method

The unlessEmpty() Method executes the callback function when the collection is not empty.

Collect.js unlessNotEmpty() Method

The unlessNotEmpty() Method executes the callback function when the collection is empty.

Collect.js unwrap() Method

The unwrap() method is used to unwrap the given collection.

Collect.js values() Method

The values() method is used to return a new collection with the given keys reset to consecutive integers.

Collect.js when() Method

The when() method is used to execute the given callback when the first argument given to the method evaluates to true.

Collect.js whenEmpty() Method

The whenEmpty() Method executes the callback function when the collection is empty.

Collect.js whenNotEmpty() Method

The whenNotEmpty() Method executes the callback function when the collection is not empty.

Collect.js where() Method

The where() Method is used to filter the collection by a given key or value contained within the given array.

Collect.js whereBetween()

The whereBetween() Method is used to filter an input within a given range. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Collect.js whereIn() Method

The whereIn() function is used to filter the collection by a given key or value contained within the given array.

Collect.js whereInstanceOf() Method

The whereInstanceOf() Method is used to filter input with a given class type. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Collect.js whereNotBetween() Method

The whereNotBetween() Method is used to filter an input which do not lie in a specified range.

Collect.js whereNotIn() Method

The whereNotIn() method in collect.js is used to filter the elements from the given collection on the basis of key and value. If particular set of key-value is found then it is filtered out.

Collect.js whereNotNull() Method

The whereNotNull() method is used to return a collection that does not contain any null values. In simple words, it filters the values that are not null.

Collect.js whereNull() Method

The whereNull() method in collect.js is used to filter the values from a collection that is null.

Collect.js wrap() Method

The wrap() method in collect.js is used to wrap a particular set of values in a collection.

Collect.js zip() Method

The zip() function is used to combine the values of given array with the values of original collection at a given index



Last Updated : 30 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads