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
Finance
How Can I Improve My Credit Score?
  How Can I Improve My Credit Score? Your credit score plays a major role in your...
By Leonard Pokrovski 2025-10-02 22:29:15 0 9K
Pharmacy
Common Pharmacy Prescriptions: A Guide to Commonly Prescribed Medications
Pharmacy prescriptions are a critical part of healthcare, helping to manage various medical...
By Dacey Rankins 2024-12-10 14:20:04 0 10K
Business
Why Do I Want to Start a Business?
Starting a business is a big decision—one that involves time, effort, and often a...
By Dacey Rankins 2025-02-05 15:53:48 0 11K
Marketing and Advertising
Common Mistakes to Avoid When Storytelling in Marketing
Storytelling has become one of the most powerful tools in modern marketing — a bridge...
By Dacey Rankins 2025-11-04 19:17:22 0 3K
Business
How Can Your Product Be Improved or Differentiated?
In today’s competitive marketplace, no product exists in isolation. Customers often have...
By Dacey Rankins 2025-08-18 13:30:56 0 7K

BigMoney.VIP Powered by Hosting Pokrov