JavaScript Map

0
12K

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
Horror
The Twilight Saga: New Moon. (2009)
Edward leaves Bella after an attack that nearly claimed her life, and, in her depression, she...
By Leonard Pokrovski 2023-05-14 19:04:25 0 28K
Business
What Are Effective Brainstorming Techniques for Startup Ideas?
Coming up with the right idea is one of the most crucial steps in launching a successful startup....
By Dacey Rankins 2025-03-24 15:19:06 0 9K
Business
What Is Viral Growth?
In the digital age, many of the fastest-growing companies—Facebook, TikTok, Dropbox, and...
By Dacey Rankins 2025-09-17 10:44:08 0 4K
Running
The Art and Science of Sports Running: A Journey of Endurance and Achievement
Running, the fundamental act of propelling oneself swiftly on foot, transcends mere physical...
By Dacey Rankins 2024-07-08 15:24:40 0 22K
Business
What Are KPIs in Sales?
KPIs are one of the most important concepts in sales — and also one of the most...
By Dacey Rankins 2025-12-15 17:22:57 0 1K

BigMoney.VIP Powered by Hosting Pokrov