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
Men's Health
Men's Health: Key Aspects and Tips for a Longer, Healthier Life
Men's health is a crucial aspect of overall well-being, encompassing physical, mental, and...
By Dacey Rankins 2024-11-21 15:52:31 0 11K
Real Estate
The Dynamics of Real Estate: A Guide to Understanding the Industry
Real estate is a multifaceted industry that encompasses a variety of activities, from buying and...
By Dacey Rankins 2024-11-27 14:24:45 0 11K
Healthcare
The Evolution and Importance of Healthcare: Ensuring Well-Being for All
Healthcare is a fundamental pillar of society, crucial not only for individual well-being but...
By Dacey Rankins 2024-11-25 15:22:50 0 11K
Business
What Are Examples of Constructive Feedback?
Constructive feedback is essential in any growth-focused environment. It helps individuals...
By Dacey Rankins 2025-07-23 12:21:36 0 4K
Arts, Culture and Entertainment
Mank (2020)
In 1940, film studio RKO 1940 hires 24-year-old wunderkind Orson Welles under a contract that...
By Leonard Pokrovski 2022-09-30 20:30:29 0 28K

BigMoney.VIP Powered by Hosting Pokrov