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
Life Issues
In the Name of the Father. (1993)
A man's coerced confession to an I.R.A. bombing he did not commit results in the imprisonment of...
By Leonard Pokrovski 2023-03-28 20:04:10 0 29K
Human Resources
How Does Offshoring Affect the Economy?
Offshoring is one of the most influential forces shaping the modern global economy. By relocating...
By Dacey Rankins 2026-03-30 17:34:13 0 3K
Social Issues
A Christmas Gift from Bob (2020)
A struggling street musician finds himself the target of an animal welfare investigation that...
By Leonard Pokrovski 2022-10-07 22:30:32 0 33K
Business
Is Cloud Infrastructure Cheaper Than On-Premises Servers?
A curious thing happens when organizations discuss technology costs. The conversation often...
By Dacey Rankins 2026-06-04 00:42:38 0 2K
Personal Finance
How Much Should I Save for Retirement — and When Can I Retire?
How Much Should I Save for Retirement — and When Can I Retire? A Practical Guide to...
By Leonard Pokrovski 2025-11-18 21:11:55 0 7K

BigMoney.VIP Powered by Hosting Pokrov