Set
Manage data collection
const set = new Set([1, 2, 3, 4, 5]);
console.log(set);Metody
add(): Adds a new element to theSet.delete(): Removes an element from theSet.has(): Checks if an element exists in theSet.clear(): Removes all elements from theSet.keys()andvalues(): Both returns aSetIteratorthat contains the values of theSet. They are the same becausekeys()is an alias forvalues().forEach(): for iterating over the values of theSet.
WeakSets
- Memory use, na hovno
Maps
- key-value pair
- Stejný princip jako Dictionary PY
const map = new Map([
['flower', 'rose'],
['fruit', 'apple'],
['vegetable', 'carrot']
]);
console.log(map); // Map(3) { 'flower' => 'rose', 'fruit' => 'apple', 'vegetable' => 'carrot' }Metody
set(): Adds a new key-value pair to theMap.get(): Retrieves the value of a key from theMap.delete(): Removes a key-value pair from theMap.has(): Checks if a key exists in theMap.clear(): Removes all key-value pairs from theMap.
WeakMaps
- Memory use, na hovno