JavaScript Map

0
13K

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
Financial Services
The economics of pollution
Key Points Economic production can cause environmental damage. This tradeoff...
By Mark Lorenzo 2023-07-20 18:29:02 0 17K
Decision Making and Problem Solving
Why do people fear losses more than gains?
Why Do People Fear Losses More Than Gains? The Asymmetry That Shows Up Everywhere A person is...
By Michael Pokrovski 2026-06-08 20:45:33 0 2K
Business
What Is Good–Better–Best (Tiered) Pricing?
When businesses want to appeal to a broad range of customers while maximizing revenue, they often...
By Dacey Rankins 2025-09-04 12:17:08 0 9K
Economics
What is the worst inflation in history?
What Is the Worst Inflation in History? Inflation is a normal part of a growing economy, but...
By Leonard Pokrovski 2026-07-27 19:58:38 0 2K
Decision Making and Problem Solving
Is caffeine good for memory?
The mind is not a warehouse, and it is certainly not a hard drive. We operate under the...
By Michael Pokrovski 2026-07-15 13:31:21 0 368

BigMoney.VIP Powered by Hosting Pokrov