The type of items in the collection
Creates a new Collection instance
The items to initialize the collection with
Readonly
[unscopables]Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
[iterator]?: booleanOptional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
at?: booleanOptional
concat?: booleanOptional
copyWithin?: booleanOptional
entries?: booleanOptional
every?: booleanOptional
fill?: booleanOptional
filter?: booleanOptional
find?: booleanOptional
findIndex?: booleanOptional
flat?: booleanOptional
flatMap?: booleanOptional
forEach?: booleanOptional
includes?: booleanOptional
indexOf?: booleanOptional
join?: booleanOptional
keys?: booleanOptional
lastIndexOf?: booleanOptional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Optional
map?: booleanOptional
pop?: booleanOptional
push?: booleanOptional
reduce?: booleanOptional
reduceRight?: booleanOptional
reverse?: booleanOptional
shift?: booleanOptional
slice?: booleanOptional
some?: booleanOptional
sort?: booleanOptional
splice?: booleanOptional
toLocaleString?: booleanOptional
toString?: booleanOptional
unshift?: booleanOptional
values?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Static
Readonly
[species]Iterator
Returns the item that comes after the first item that matches the given key/value pair or callback
Optional
value: anyThe value to match (only used when keyOrCallback is a key)
Optional
strict: boolean = falseWhether to use strict equality comparison
The next item in the collection or null if not found
Takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.
Returns the item that comes before the first item that matches the given key/value pair or callback
The key to match against, a callback function, or a direct value
Optional
value: anyThe value to match (only used when keyOrCallbackOrValue is a key)
Optional
strict: boolean = trueWhether to use strict equality comparison
The previous item in the collection or null if not found
Splits the collection into chunks of the specified size
The size of each chunk
A new collection containing arrays of chunked items
Converts the collection into a new Collection instance
A new Collection instance containing the same items
Concatenates the current collection with the given items
The items to concatenate
A new Collection instance containing the concatenated items
Checks if the collection contains an item that matches the given key/value pair, callback, or direct value
The key to match against, a callback function, or a direct value
Optional
value: anyThe value to match (only used when keyOrCallbackOrValue is a key)
True if the collection contains a matching item, false otherwise
Checks if the collection contains an item that matches the given key/value pair, callback, or direct value
The key to match against, a callback function, or a direct value
Optional
value: anyThe value to match (only used when keyOrCallbackOrValue is a key)
True if the collection contains a matching item, false otherwise
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
If target is negative, it is treated as length+target where length is the length of the array.
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
Optional
end: numberIf not specified, length of the this object is used as its default value.
Returns the number of items in the collection
The number of items in the collection
Counts the occurrences of each unique value in the collection
Optional
callback: (item: T) => anyA callback function to determine the value to count
A Collection containing an object with counts of each unique value
Checks if the collection does not contain an item that matches the given predicate or key/value pair
A callback function, value, or key to match against
Optional
value: anyThe value to match (only used for key-value pairs)
True if the collection does not contain a matching item, false otherwise
Finds duplicate values in the collection
Optional
key: keyof TThe key to check for duplicates (only for collections of objects)
An object with indices as keys and duplicate values
Iterates over each item in the collection and executes the callback function
The callback function to execute
The current collection instance
Returns an iterable of key, value pairs for every entry in the array
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Removes the specified keys from each item in the collection
A new collection with the keys removed
Changes all array elements from start
to end
index to a static value
and returns the modified array
value to fill array section with
Optional
start: numberindex to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.
Optional
end: numberindex to stop filling the array at. If end is negative, it is treated as length+end.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns the first item in the collection that matches the given key/operator/value condition
The first matching item or null if not found
Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.
A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.
Optional
thisArg: ThisAn object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Returns a subset of the collection for the specified page and items per page
The page number (1-based)
The number of items per page
A new collection containing the items for the specified page
Retrieves the value of the specified key from the first item in the collection
The key to retrieve
Optional
defaultValue: any = nullThe default value to return if the key is not found
The value of the key or the default value
Groups the items in the collection by the specified key or callback
The key to group by or a callback function
A new collection containing the grouped items
Checks if the collection contains items with the specified keys
The keys to check for
True if the collection contains items with the specified keys, false otherwise
Checks if the collection contains items with any of the specified keys
The keys to check for
True if the collection contains items with any of the specified keys, false otherwise
Joins the values of the collection into a string
The key to join or the glue string
Optional
glue: stringThe string to use as a separator
The joined string
Determines whether an array includes a certain element, returning true or false as appropriate.
The element to search for.
Optional
fromIndex: numberThe position in this array at which to begin searching for searchElement.
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
The value to locate in the array.
Optional
fromIndex: numberThe array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Checks if the collection is empty
True if the collection is empty, false otherwise
Checks if every item in the collection matches the given callback or key/value pair
A callback function or key to match against
Optional
value: anyThe value to match (only used when callbackOrKey is a key)
True if every item matches, false otherwise
Checks if the collection is not empty
True if the collection is not empty, false otherwise
Adds all the elements of an array into a string, separated by the specified separator string.
Optional
separator: stringA string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
Returns an iterable of keys in the array
Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
The value to locate in the array.
Optional
fromIndex: numberThe array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Finds the maximum value in the collection based on the specified key
Optional
key: keyof TThe key to find the maximum value for
The maximum value or null if the collection is empty
Finds the median value in the collection based on the specified key
Optional
key: keyof TThe key to find the median value for
The median value or null if the collection is empty
Finds the minimum value in the collection based on the specified key
Optional
key: keyof TThe key to find the minimum value for
The minimum value or null if the collection is empty
Multiplies the collection by the specified number of times
The number of times to multiply the collection
A new collection containing the multiplied items
Returns a new collection containing every nth item in the collection
The step size
Optional
offset: number = 0The offset to start from
A new collection containing every nth item
Returns a new collection containing only the specified keys from each item
The keys to include
A new collection containing only the specified keys
Extracts the values of the specified fields from each item in the collection
The field to extract
A new collection containing the extracted values
Extracts the values of the specified fields from each item in the collection
A new collection containing the extracted values
Extracts the values of the specified fields from each item in the collection
A new collection containing the extracted values
Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.
Removes the specified key from each object in the collection
The key to remove
The updated collection with the key removed
Appends new elements to the end of an array, and returns the new length of the array.
New elements to add to the array.
Returns a random item or a collection of random items from the collection
Optional
count: number | ((collection: Collection<T>) => any)The number of random items to return or a callback function
A random item or a collection of random items
Filters the collection to include items within the specified range
The key to filter by
The range to include
A new collection containing items within the range
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array.
Selects the specified keys from each item in the collection
The keys to select
A new collection containing the selected keys
Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.
Shuffles the items in the collection
A new collection containing the shuffled items
Skips the first n items in the collection
The number of items to skip
A new collection containing the remaining items
Skips items in the collection until the callback condition is met
Optional
callback: (item: T) => booleanA callback function to determine when to stop skipping
A new collection containing the remaining items
Optional
callback: (item: T) => booleanReturns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.
Optional
start: numberThe beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.
Optional
end: numberThe end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.
Creates sliding windows of the specified size and step
The size of each window
Optional
step: number = 1The step size between windows
A new collection containing the sliding windows
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Sorts an array in place. This method mutates the array and returns a reference to the same array.
Optional
compareFn: (a: T, b: T) => numberFunction used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order.
[11,2,22,1].sort((a, b) => a - b)
Sorts the collection in descending order
A new collection containing the sorted items
Sorts the collection by keys in ascending order
A new collection containing the sorted items
Sorts the collection by keys in descending order
A new collection containing the sorted items
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
The zero-based location in the array from which to start removing elements.
Optional
deleteCount: numberThe number of elements to remove.
An array containing the elements that were deleted.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
The zero-based location in the array from which to start removing elements.
The number of elements to remove.
Elements to insert into the array in place of the deleted elements.
An array containing the elements that were deleted.
Splits the collection into the specified number of groups
The number of groups to split into
An array of collections, each containing a group of items
Splits the collection into the specified number of groups with balanced sizes
The number of groups to split into
An array of collections, each containing a group of items
Returns a subset of the collection with the specified number of items
The number of items to take
A new collection containing the taken items
Returns a subset of the collection until the callback condition is met
A new collection containing the taken items
Returns a subset of the collection while the callback condition is true
A new collection containing the taken items
Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
Optional
options: NumberFormatOptions & DateTimeFormatOptionsReturns a string representation of an array.
Returns a new collection containing unique items based on the specified key or callback
A new collection containing unique items
Returns a new collection containing unique items based on the specified key or callback
A new collection containing unique items
Returns a new collection containing unique items based on the specified key or callback
A new collection containing unique items
Inserts new elements at the start of an array, and returns the new length of the array.
Elements to insert at the start of the array.
Returns an iterable of values in the array
Filters the collection to include items that match the specified key/operator/value condition
A new collection containing the matching items
Filters the collection to include items with values in the specified array
A new collection containing items with values in the array
Filters the collection to exclude items with values in the specified array
A new collection containing items without values in the array
Filters the collection to include items with non-null values for the specified key
The key to filter by
A new collection containing items with non-null values
Filters the collection to include items with null values for the specified key
The key to filter by
A new collection containing items with null values
Static
fromStatic
isStatic
makeCreates a new collection instance with the specified items
The items to include in the new collection
A new collection instance
Static
of
Collection class that extends Array to provide additional functionality for working with arrays of items Collection