Returns an iterable of entries in the map.
Creates an ordered array of the values of this collection, and caches it internally. The array will only be
reconstructed if an item is added to or removed from the collection, or if you change the length of the array
itself. If you don't want this caching behavior, use [...collection.values()]
or
Array.from(collection.values())
instead.
Identical to Map.clear(). Removes all elements from the collection.
Creates an identical shallow copy of this collection.
Combines this collection with others into a new collection. None of the source collections are modified.
Collections to merge
Identical to Map.delete(). Deletes an element from the collection.
The key to delete from the collection
true
if the element was removed, false
if the element does not exist.
The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
The other Collection to filter against
Identical to Map.forEach(), but returns the collection instead of undefined.
Function to execute for each element
Returns an iterable of key, value pairs for every entry in the map.
Checks if this collection shares identical items with another. This is different to checking for equality using equal-signs, because the collections may be different objects, but contain the same data.
Collection to compare with
Whether the collections have identical contents
Checks if all items passes a test. Identical in behavior to Array.every().
Function used to test (should return a boolean)
Identical to Array.filter(), but returns a Collection instead of an Array.
The function to test with (should return boolean)
Searches for a single item where the given function returns a truthy value. This behaves like
Array.find().
id
property, and if you want to find by id you
should use the get
method. See
MDN for details.
The function to test with (should return boolean)
Searches for the key of a single item where the given function returns a truthy value. This behaves like Array.findIndex(), but returns the key rather than the positional index.
The function to test with (should return boolean)
Obtains the first value(s) in this collection.
A single value if no amount is provided or an array of values, starting from the end if amount is negative
Obtains the first key(s) in this collection.
A single key if no amount is provided or an array of keys, starting from the end if amount is negative
Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().
Function that produces a new Collection
Identical to Map.get().
Gets an element with the specified key, and returns its value, or undefined
if the element does not exist.
The key to get from this collection
Identical to Map.has(). Checks if an element exists in the collection.
The key of the element to check for
true
if the element exists, false
if it does not exist.
The intersect method returns a new structure containing items where the keys are present in both original structures.
The other Collection to filter against
Creates an ordered array of the keys of this collection, and caches it internally. The array will only be
reconstructed if an item is added to or removed from the collection, or if you change the length of the array
itself. If you don't want this caching behavior, use [...collection.keys()]
or
Array.from(collection.keys())
instead.
Returns an iterable of keys in the map
Obtains the last value(s) in this collection. This relies on {@link Collection#array}, and thus the caching mechanism applies here as well.
A single value if no amount is provided or an array of values, starting from the start if amount is negative
Obtains the last key(s) in this collection. This relies on {@link Collection#keyArray}, and thus the caching mechanism applies here as well.
A single key if no amount is provided or an array of keys, starting from the start if amount is negative
Maps each item to another value into an array. Identical in behavior to Array.map().
Function that produces an element of the new array, taking three arguments
Maps each item to another value into a collection. Identical in behavior to Array.map().
Function that produces an element of the new collection, taking three arguments
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
Function used to test (should return a boolean)
Obtains unique random value(s) from this collection. This relies on {@link Collection#array}, and thus the caching mechanism applies here as well.
A single value if no amount is provided or an array of values
Obtains unique random key(s) from this collection. This relies on {@link Collection#keyArray}, and thus the caching mechanism applies here as well.
A single key if no amount is provided or an array
Applies a function to produce a single value. Identical in behavior to Array.reduce().
Function used to reduce, taking four arguments; accumulator
, currentValue
, currentKey
,
and collection
Identical to Map.set(). Sets a new element in the collection with the specified key and value.
The key of the element to add
The value of the element to add
Checks if there exists an item that passes a test. Identical in behavior to Array.some().
Function used to test (should return a boolean)
The sort method sorts the items of a collection in place and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.
The sorted method sorts the items of a collection and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.
Removes items that satisfy the provided filter function.
Function used to test (should return a boolean)
The number of removed entries
Runs a function on the collection and returns the collection.
Function to execute
Returns an iterable of values in the map
Generated using TypeDoc
A Map with additional utility methods. This is used throughout Typescript/Javascript Discord libraries rather than Arrays for anything that has an ID, for significantly improved performance and ease-of-use.
{number} size - The amount of elements in this collection.