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
Economics
What role did Adam Smith play in free market theory?
What Role Did Adam Smith Play in Free Market Theory? The Man Most People Quote—and Few...
By Leonard Pokrovski 2026-06-03 01:16:20 0 2K
Business
How Can I Reduce Shipping Costs on Marketplaces?
Shipping costs rarely arrive as a single line item. They creep in. Box by box. Order by order....
By Dacey Rankins 2026-06-18 16:05:55 0 2K
Business
How Do I Cancel a Membership?
At first glance, canceling a membership seems simple. Click a button. Send an email. Call...
By Dacey Rankins 2026-06-26 00:00:38 0 2K
Decision Making and Problem Solving
What are brainstorming techniques?
How Can I Think Outside the Box? The box is rarely visible. That is what makes it powerful. A...
By Michael Pokrovski 2026-06-20 19:32:05 0 1K
Business
B2C: what it is, the difference, the stages of construction
In this article, we will learn what B2C sales are, what is the difference between B2C, B2B, and...
By Dacey Rankins 2024-09-24 14:30:17 0 24K

BigMoney.VIP Powered by Hosting Pokrov