JavaScript Map

0
7K

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
Teen Health
Adolescent and Youth Health
Key facts In 2020, there were over 1.5 million deaths of adolescents and young people aged...
By FWhoop Xelqua 2022-11-22 14:00:47 0 29K
Жизненные вопросы
История семьи Блум. Penguin Bloom. (2021)
Сэм та долго и старательно готовилась к отпуску в кругу семьи в Таиланде, что была настроена на...
By Nikolai Pokryshkin 2022-09-17 10:30:49 1 26K
Arts
Investments in art. How much can you earn from masterpieces?
Works of art, in addition to cultural value, also have material value. Moreover, their value is...
By Michael Pokrovski 2024-03-11 21:17:45 0 20K
Business
What Is Corporate Social Responsibility (CSR)?
Corporate Social Responsibility (CSR) refers to a company’s commitment to managing its...
By Dacey Rankins 2025-01-31 15:27:35 0 5K
Business
Cybernetics
Cybernetics Cybernetics (from Ancient...
By Leonard Pokrovski 2024-08-21 01:08:17 0 15K
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov