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
Customer Service
How Do You Deal With Difficult Customers?
Dealing with difficult customers is a common challenge in customer service roles. Customers may...
By Dacey Rankins 2026-03-10 19:57:25 0 4K
Programming
Python Aiohttp Proxies
The following example shows how to use aiohttp to handle HTTP requests. We’ll send an...
By Jesse Thomas 2023-03-14 21:45:07 0 12K
Radio
Rediscovering Recreation: The Art of Entertainment Through Radio
Rediscovering Recreation: The Art of Entertainment Through Radio In an era of dazzling visual...
By Leonard Pokrovski 2024-05-14 22:18:37 0 22K
Business
What role does leadership play in crisis management?
In times of crisis, the effectiveness of an organization’s response largely depends on the...
By Dacey Rankins 2025-01-17 16:52:39 0 10K
Marketing and Advertising
How Do Startups Acquire Customers?
Customer acquisition is arguably the most critical challenge for startups. No matter how...
By Dacey Rankins 2026-01-16 16:39:43 0 6K

BigMoney.VIP Powered by Hosting Pokrov