JavaScript Map

0
11K

Map objects are collections of key-value pairs. A key in the Map may only occur once; it is unique in the Map's collection. A Map object is iterated by key-value pairs — a for...of loop returns a 2-member array of [key, value] for each iteration. Iteration happens in insertion order, which corresponds to the order in which each key-value pair was first inserted into the map by the set() method (that is, there wasn't a key with the same value already in the map when set() was called).

The specification requires maps to be implemented "that, on average, provide access times that are sublinear on the number of elements in the collection". Therefore, it could be represented internally as a hash table (with O(1) lookup), a search tree (with O(log(N)) lookup), or any other data structure, as long as the complexity is better than O(N).

Key equality

Value equality is based on the SameValueZero algorithm. (It used to use SameValue, which treated 0 and -0 as different. Check browser compatibility.) This means NaN is considered the same as NaN (even though NaN !== NaN) and all other values are considered equal according to the semantics of the === operator.

Căutare
Categorii
Citeste mai mult
Life Issues
Me Before You. (2016)
A girl in a small town forms an unlikely bond with a recently-paralyzed man she's taking care of....
By Leonard Pokrovski 2023-05-20 14:43:09 0 37K
Социальные проблемы
Афера. The Sting. (1973)
В 1930-е годы двое отпетых мошенников пытаются отомстить главарю мафии за смерть их общего друга...
By Nikolai Pokryshkin 2023-01-24 08:52:46 0 33K
Социальные проблемы
Карты, деньги, два ствола. Lock, Stock and Two Smoking Barrels. (1998)
Четверо молодых парней накопили каждый по 25 тысяч фунтов, чтобы один из них мог сыграть в карты...
By Nikolai Pokryshkin 2023-03-04 12:57:43 0 31K
Pets
Exploring the World of Pet Shopping: From Essentials to Luxuries
Exploring the World of Pet Shopping: From Essentials to Luxuries In recent years, the way we...
By Leonard Pokrovski 2024-06-01 11:55:21 0 30K
Business
What Is CEO Succession?
CEO succession is a critical process that ensures the continued leadership and stability of an...
By Dacey Rankins 2025-06-16 14:59:28 0 5K

BigMoney.VIP Powered by Hosting Pokrov