Collection
Represents a collection that extends the built-in Map class.
Extends
Map
<K
,V
>
Type parameters
Type parameter | Description |
---|---|
K | The type of the keys in the collection. |
V | The type of the values in the collection. |
Constructors
new Collection(entries)
Parameters
Parameter | Type |
---|---|
entries ? | null | readonly readonly [K , V ][] |
Returns
Collection
<K
, V
>
Inherited from
Map<K, V>.constructor
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:50
new Collection(iterable)
Parameters
Parameter | Type |
---|---|
iterable ? | null | Iterable <readonly [K , V ]> |
Returns
Collection
<K
, V
>
Inherited from
Map<K, V>.constructor
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:49
Properties
Property | Modifier | Type | Description | Inherited from |
---|---|---|---|---|
[toStringTag] | readonly | string | - | Map.[toStringTag] |
size | readonly | number | Map.size | |
[species] | readonly | MapConstructor | - | Map.[species] |
Methods
[iterator]
()
Returns an iterable of entries in the map.
Returns
IterableIterator
<[K
, V
]>
Inherited from
Map.[iterator]
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.iterable.d.ts:119
clear()
Returns
void
Inherited from
Map.clear
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:20
delete()
Parameters
Parameter | Type |
---|---|
key | K |
Returns
boolean
true if an element in the Map existed and has been removed, or false if the element does not exist.
Inherited from
Map.delete
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:24
entries()
Returns an iterable of key, value pairs for every entry in the map.
Returns
IterableIterator
<[K
, V
]>
Inherited from
Map.entries
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.iterable.d.ts:124
every()
Checks if all elements in the collection pass a test implemented by the provided function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => boolean | The function to test each element of the collection. |
Returns
boolean
true
if all elements pass the test, otherwise false
.
Example
Source
filter()
Creates a new array with all elements that pass the test implemented by the provided function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => boolean | The function to test each element of the collection. |
Returns
V
[]
A new array with the elements that pass the test.
Example
Source
find()
Returns the value of the first element in the collection that satisfies the provided testing function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => boolean | The function to test each element of the collection. |
Returns
undefined
| V
The value of the first element that passes the test. undefined
if no element passes the test.
Example
Source
findKey()
Returns the first key in the collection that satisfies the provided testing function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => boolean | The function to test each element of the collection. |
Returns
undefined
| K
The first key that passes the test. undefined
if no element passes the test.
Example
Source
forEach()
Executes a provided function once per each key/value pair in the Map, in insertion order.
Parameters
Parameter | Type |
---|---|
callbackfn | (value : V , key : K , map : Map <K , V >) => void |
thisArg ? | any |
Returns
void
Inherited from
Map.forEach
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:28
get()
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
Parameters
Parameter | Type |
---|---|
key | K |
Returns
undefined
| V
Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
Inherited from
Map.get
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:33
has()
Parameters
Parameter | Type |
---|---|
key | K |
Returns
boolean
boolean indicating whether an element with the specified key exists or not.
Inherited from
Map.has
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:37
keys()
Returns an iterable of keys in the map
Returns
IterableIterator
<K
>
Inherited from
Map.keys
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.iterable.d.ts:129
map()
Creates a new array with the results of calling a provided function on every element in the collection.
Type parameters
Type parameter | Value |
---|---|
T | any |
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => T | The function that produces an element of the new array. |
Returns
T
[]
A new array with the results of calling the provided function on every element in the collection.
Example
Source
reduce()
Apply a function against an accumulator and each element in the collection (from left to right) to reduce it to a single value.
Type parameters
Type parameter | Value |
---|---|
T | any |
Parameters
Parameter | Type | Description |
---|---|---|
fn | (accumulator : T , value : V , key : K , collection : this ) => T | The function to execute on each element in the collection. |
initialValue ? | T | The initial value of the accumulator. |
Returns
T
The value that results from the reduction.
Example
Source
set()
Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
Parameters
Parameter | Type |
---|---|
key | K |
value | V |
Returns
this
Inherited from
Map.set
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.collection.d.ts:41
some()
Checks if at least one element in the collection passes a test implemented by the provided function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => boolean | The function to test each element of the collection. |
Returns
boolean
true
if at least one element passes the test, otherwise false
.
Example
Source
sweep()
Removes elements from the collection based on a filter function.
Parameters
Parameter | Type | Description |
---|---|---|
fn | (value : V , key : K , collection : this ) => unknown | The filter function that determines which elements to remove. |
Returns
number
The number of elements removed from the collection.
Example
Source
values()
Returns an iterable of values in the map
Returns
IterableIterator
<V
>
Inherited from
Map.values
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.es2015.iterable.d.ts:134
groupBy()
Groups members of an iterable according to the return value of the passed callback.
Type parameters
Type parameter |
---|
K |
T |
Parameters
Parameter | Type | Description |
---|---|---|
items | Iterable <T > | An iterable. |
keySelector | (item : T , index : number ) => K | A callback which will be invoked for each item in items. |
Returns
Map
<K
, T
[]>
Inherited from
Map.groupBy
Source
node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/lib.esnext.collection.d.ts:25