collections-x
ES6 collections fallback library: Map and Set.
- collections-x
.isMap
⇒boolean
.isSet
⇒boolean
.MapConstructor
.SetConstructor
.add
⇒Object
.clear
⇒Object
.delete
⇒boolean
.forEach
⇒Object
.size
:number
.entries()
⇒Object
.has(value)
⇒boolean
.keys()
⇒Object
.values()
⇒Object
.symIt()
⇒Object
.symIt
collections-x.isMap
⇒ boolean
Determine if an object
is a Map
.
Kind: static property of collections-x
Returns: boolean
- true
if the object
is a Map
,
else false
.
Param | Type | Description |
---|---|---|
object | * |
The object to test. |
Example
; const m = ; console; // falseconsole; // falseconsole; // true
collections-x.isSet
⇒ boolean
Determine if an object
is a Set
.
Kind: static property of collections-x
Returns: boolean
- true
if the object
is a Set
,
else false
.
Param | Type | Description |
---|---|---|
object | * |
The object to test. |
Example
; const s = ; console; // falseconsole; // falseconsole; // true
collections-x.MapConstructor
Kind: static property of collections-x
map.clear
⇒ Object
The clear() method removes all elements from a Map object.
Kind: instance property of Map
Returns: Object
- The Map object.
Example
; const myMap = ;myMap;myMap; console; // 2console; // true myMapclear; console; // 0console; // false
map.delete
⇒ boolean
The delete() method removes the specified element from a Map object.
Kind: instance property of Map
Returns: boolean
- Returns true if an element in the Map object has been
removed successfully.
Param | Type | Description |
---|---|---|
key | * |
The key of the element to remove from the Map object. |
Example
; const myMap = ;myMap; myMap; // Returns true. Successfully removed.myMap; // Returns false.// The "bar" element is no longer present.
map.entries
⇒ Object
The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.
Kind: instance property of Map
Returns: Object
- A new Iterator object.
Example
;const myMap = ;myMap;myMap;myMap; const mapIter = myMap; console; // ["0", "foo"]console; // [1, "bar"]console; // [Object, "baz"]
map.forEach
⇒ Object
The forEach() method executes a provided function once per each key/value pair in the Map object, in insertion order.
Kind: instance property of Map
Returns: Object
- The Map object.
Param | Type | Description |
---|---|---|
callback | function |
Function to execute for each element. |
[thisArg] | * |
Value to use as this when executing callback. |
Example
; { console;} const myMap = 'foo' 3 'bar' {} 'baz' undefined;myMap;// logs:// "m[foo] = 3"// "m[bar] = [object Object]"// "m[baz] = undefined"
map.get
⇒ *
The get() method returns a specified element from a Map object.
Kind: instance property of Map
Returns: *
- Returns the element associated with the specified key or
undefined if the key can't be found in the Map object.
Param | Type | Description |
---|---|---|
key | * |
The key of the element to return from the Map object. |
Example
; const myMap = ;myMap; myMap; // Returns "foo".myMap; // Returns undefined.
map.keys
⇒ Object
The keys() method returns a new Iterator object that contains the keys for each element in the Map object in insertion order.
Kind: instance property of Map
Returns: Object
- A new Iterator object.
Example
; const myMap = ;myMap;myMap;myMap; const mapIter = myMap; console; // "0"console; // 1console; // Object
map.set
⇒ Object
The set() method adds a new element with a specified key and value to a Map object.
Kind: instance property of Map
Returns: Object
- The Map object.
Param | Type | Description |
---|---|---|
key | * |
The key of the element to add to the Map object. |
value | * |
The value of the element to add to the Map object. |
Example
; const myMap = ; // Add new elements to the mapmyMap;myMap; // Update an element in the mapmyMap;
map.size
: number
The value of size is an integer representing how many entries the Map object has.
Kind: instance property of Map
Example
; const myMap = ;myMap;myMap;myMap; console; // 3
map.values
⇒ Object
The values() method returns a new Iterator object that contains the values for each element in the Map object in insertion order.
Kind: instance property of Map
Returns: Object
- A new Iterator object.
Example
; const myMap = ;myMap;myMap;myMap; const mapIter = myMap; console; // "foo"console; // "bar"console; // "baz"
map.has(key)
⇒ boolean
The has() method returns a boolean indicating whether an element with the specified key exists or not.
Kind: instance method of Map
Returns: boolean
- Returns true if an element with the specified key
exists in the Map object; otherwise false.
Param | Type | Description |
---|---|---|
key | * |
The key of the element to test for presence in the Map object. |
Example
; const myMap = ;myMap; myMap; // returns truemyMap; // returns false
map.symIt()
⇒ Object
The initial value of the @@iterator property is the same function object as the initial value of the entries property.
Kind: instance method of Map
Returns: Object
- A new Iterator object.
Example
; const myMap = ;myMap;myMap;myMap; var mapIter = myMapsymIt; console; // ["0", "foo"]console; // [1, "bar"]console; // [Object, "baz"]
collections-x.SetConstructor
Kind: static property of collections-x
.SetConstructor
.add
⇒Object
.clear
⇒Object
.delete
⇒boolean
.forEach
⇒Object
.size
:number
.entries()
⇒Object
.has(value)
⇒boolean
.keys()
⇒Object
.values()
⇒Object
.symIt()
⇒Object
set.add
⇒ Object
The add() method appends a new element with a specified value to the end of a Set object.
Kind: instance property of Set
Returns: Object
- The Set object.
Param | Type | Description |
---|---|---|
value | * |
Required. The value of the element to add to the Set object. |
Example
; const mySet = ; mySet;mySet; // chainable console;// Set [1, 5, "some text"]
set.clear
⇒ Object
The clear() method removes all elements from a Set object.
Kind: instance property of Set
Returns: Object
- The Set object.
Example
; const mySet = ;mySet;mySet; console; // 2mySet; // true mySetclear; console; // 0mySet; // false
set.delete
⇒ boolean
The delete() method removes the specified element from a Set object.
Kind: instance property of Set
Returns: boolean
- Returns true if an element in the Set object has been
removed successfully; otherwise false.
Param | Type | Description |
---|---|---|
value | * |
The value of the element to remove from the Set object. |
Example
; const mySet = ;mySet; mySet; // Returns false. No "bar" element found//to be deleted.mySet; // Returns true. Successfully removed. mySet; // Returns false. The "foo" element is no//longer present.
set.forEach
⇒ Object
The forEach() method executes a provided function once per each value in the Set object, in insertion order.
Kind: instance property of Set
Returns: Object
- The Set object.
Param | Type | Description |
---|---|---|
callback | function |
Function to execute for each element. |
[thisArg] | * |
Value to use as this when executing callback. |
Example
{ console;} 'foo' 'bar' undefined; // logs:// "s[foo] = foo"// "s[bar] = bar"// "s[undefined] = undefined"
set.size
: number
The value of size is an integer representing how many entries the Set object has.
Kind: instance property of Set
Example
; const mySet = ;mySet;mySet;mySet; console; // 3
set.entries()
⇒ Object
The entries() method returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in insertion order. For Set objects there is no key like in Map objects. However, to keep the API similar to the Map object, each entry has the same value for its key and value here, so that an array [value, value] is returned.
Kind: instance method of Set
Returns: Object
- A new Iterator object.
Example
; const mySet = ;mySet;mySet;mySet; const setIter = mySet; console; // ["foobar", "foobar"]console; // [1, 1]console; // ["baz", "baz"]
set.has(value)
⇒ boolean
The has() method returns a boolean indicating whether an element with the specified value exists in a Set object or not.
Kind: instance method of Set
Returns: boolean
- Returns true if an element with the specified value
exists in the Set object; otherwise false.
Param | Type | Description |
---|---|---|
value | * |
The value to test for presence in the Set object. |
Example
; const mySet = ;mySet; mySet; // returns truemySet; // returns false
set.keys()
⇒ Object
The keys() method is an alias for the values
method (for similarity
with Map objects); it behaves exactly the same and returns values of
Set elements.
Kind: instance method of Set
Returns: Object
- A new Iterator object.
Example
; const mySet = ;mySet;mySet;mySet; const setIter = mySet; console; // "foo"console; // "bar"console; // "baz"
set.values()
⇒ Object
The values() method returns a new Iterator object that contains the values for each element in the Set object in insertion order.
Kind: instance method of Set
Returns: Object
- A new Iterator object.
Example
; const mySet = ;mySet;mySet;mySet; const setIter = mySet; console; // "foo"console; // "bar"console; // "baz"
set.symIt()
⇒ Object
The initial value of the @@iterator property is the same function object as the initial value of the values property.
Kind: instance method of Set
Returns: Object
- A new Iterator object.
Example
; const mySet = ;mySet;mySet;mySet; const setIter = mySetsymIt; console; // "0"console; // 1console; // Object
collections-x.symIt
The iterator identifier that is in use.
type {Symbol|string}
Kind: static property of collections-x