Map

Property Summary

TypeNameSummary

The size accessor property returns the number of elements in a Map object..

Methods Summary

TypeNameSummary

void

The clear() method removes all elements from a Map object..

The delete() method removes the specified element from a Map object by key..

The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Map object in insertion order..

void

The forEach() method executes a provided function once for each value in the Map object, in insertion order..

The get() method returns a specified element from a Map object..

The has() method returns a boolean indicating whether an element with the specified key exists in a Map object or not..

The keys() method returns a new iterator object that contains the keys for each element in the Map object in insertion order..

The set() method adds or updates an entry in a Map object with a specified key and a value..

The values() method returns a new iterator object that contains the values for each element in the Map object in insertion order..

Properties Details

size

The size accessor property returns the number of elements in a Map object.

Returns Number

Sample

map.size;

Methods Details

clear()

The clear() method removes all elements from a Map object.

Returns void

Sample

map.clear();

delete(key)

The delete() method removes the specified element from a Map object by key.

Parameters Object key ;

Returns Boolean

Sample

var success = map.delete(key);

entries()

The entries() method returns a new iterator object that contains the [key, value] pairs for each element in the Map object in insertion order. In this particular case, this iterator object is also an iterable, so the for-of loop can be used..

Returns Iterator the iterator that can be used in for of loops

Sample

for(var entry of map.entries()) {}

forEach(callback, thisArgument)

The forEach() method executes a provided function once for each value in the Map object, in insertion order.

Parameters Function callback ; Object thisArgument ;

Returns void

Sample

map.forEach(function(keyValuePair) {});

get(key)

The get() method returns a specified element from a 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 object.

Parameters Object key ;

Returns Object

Sample

var value = map.get(key);

has(key)

The has() method returns a boolean indicating whether an element with the specified key exists in a Map object or not.

Parameters Object key ;

Returns Boolean

Sample

var containsKey = map.has(key);

keys()

The keys() method returns a new iterator object that contains the keys for each element in the Map object in insertion order. In this particular case, this iterator object is also an iterable, so a for...of loop can be used.

Returns Iterator the iterator that can be used in for of loops

Sample

var values = map.keys();

set(key, value)

The set() method adds or updates an entry in a Map object with a specified key and a value.

Parameters Object key ; Object value ;

Returns Map

Sample

map.set(keyObject, value);

values()

The values() method returns a new iterator object that contains the values for each element in the Map object in insertion order.

Returns Iterator the iterator that can be used in for of loops

Sample

var values = map.values();

Last updated