| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Keyed_collections | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
MapMap - (). /( ) .
, , :
for...of.:
var sayings = new Map();
sayings.set("dog", "woof");
sayings.set("cat", "meow").set("elephant", "toot");
// .set Map, set
sayings.set("dog", "-"); //
sayings.size; // 3
sayings.get("fox"); // undefined
sayings.has("bird"); // false
sayings.delete("dog");
for (var [key, value] of sayings) {
console.log(key + " goes " + value);
}
// "cat goes meow"
// "elephant goes toot"
Map .
WeakMapWeakMap , , WeakMap ( (garbage collector GC)).
:
WeakMap Map, - WeakMap (.e. ). , garbage collection.
, , " WeakMap?" WeakMap.
, WeakMap, , . Hiding Implementation Details with ECMAScript 6 WeakMaps (.). privates . ; :
const privates = new WeakMap();
export class Public() {
constructor() {
const me = {
//
};
// 'me' 'this' !!!
privates.set(this, me);
}
method () {
const me = privates.get(this);
// - 'me'...
}
}
SetSet - , .
Set:
var mySet = new Set();
mySet.add(1);
mySet.add("some text");
mySet.add("foo");
mySet.has(1); // true
mySet.delete("foo");
mySet.size; // 2
for (let item of mySet) console.log(item);
// 1
// "some text"
Array Set Array.from spread operator.
, Set Array .
:
Set , Array .
Array.from(mySet);
[...mySet2];
mySet2 = new Set([1, 2, 3, 4]);
Array Set, , :
Set.has Array.indexOf.NaN . WeakSetWeakSet , . WeakSet ( (garbage collector GC)).
:
WeakSet , Set.
Set:
WeakSet ( ).WeakSet . () . WeakSet . , , , , DOM-.
Map Set Map objects Set "same-value-zero algorithm":
===.-0 +0 .NaN ( ===).This page was last modified on 14 . 2025 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |