Optional
entries: null | readonly (readonly [K, V])[]Optional
thisArg: unknownOptional
thisArg: unknownIdentical 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
Identical to Map.has(). Checks if an element exists in the collection.
true
if the element exists, false
if it does not exist.
The key of the element to check for
Identical to Map.delete(). Deletes an element from the collection.
true
if the element was removed, false
if the element does not exist.
The key to delete from the collection
Identical to Map.clear(). Removes all elements from the collection.
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.
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.
Obtains the last value(s) in this collection. This relies on 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 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
Obtains unique random value(s) from this collection. This relies on 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 keyArray, and thus the caching mechanism applies here as well.
A single key if no amount is provided or an array
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.
collection.find(user => user.username === 'Bob');
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.
collection.findKey(user => user.username === 'Bob');
The function to test with (should return boolean)
Removes items that satisfy the provided filter function.
The number of removed entries
Function used to test (should return a boolean)
Identical to Array.filter(), but returns a Collection instead of an Array.
collection.filter(user => user.username === 'Bob');
The function to test with (should return boolean)
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
const [big, small] = collection.partition(guild => guild.memberCount > 250);
Function used to test (should return a boolean)
Maps each item to another value into an array. Identical in behavior to Array.map().
collection.map(user => user.tag);
Function that produces an element of the new array, taking three arguments
Checks if there exists an item that passes a test. Identical in behavior to Array.some().
collection.some(user => user.discriminator === '0000');
Function used to test (should return a boolean)
Checks if all items passes a test. Identical in behavior to Array.every().
collection.every(user => !user.bot);
Function used to test (should return a boolean)
Applies a function to produce a single value. Identical in behavior to Array.reduce().
collection.reduce((acc, guild) => acc + guild.memberCount, 0);
Function used to reduce, taking four arguments; accumulator
, currentValue
, currentKey
,
and collection
Optional
initialValue: TStarting value for the accumulator
Identical to Map.forEach(), but returns the collection instead of undefined.
collection
.each(user => console.log(user.username))
.filter(user => user.bot)
.each(user => console.log(user.username));
Function to execute for each element
Runs a function on the collection and returns the collection.
collection
.tap(coll => console.log(coll.size))
.filter(user => user.bot)
.tap(coll => console.log(coll.size))
Function to execute
Creates an identical shallow copy of this collection.
const newColl = someColl.clone();
Combines this collection with others into a new collection. None of the source collections are modified.
const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
Rest
...collections: Collection<K, V>[]Collections to merge
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.
Whether the collections have identical contents
Collection to compare with
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.
collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
Optional
compareFunction: ((firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number)Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
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
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.
collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
Optional
compareFunction: ((firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number)Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
Executes a provided function once per each key/value pair in the Map, in insertion order.
Optional
thisArg: anyReadonly
sizethe number of elements in the Map.
Readonly
[toStatic
Readonly
defaultStatic
Readonly
[species]Generated using TypeDoc
Identical to Map.get(). Gets an element with the specified key, and returns its value, or
undefined
if the element does not exist.Returns