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
Finance
Which Finance Biography Books Are More Suitable for Beginners vs. More Advanced Readers?
Which Finance Biography Books Are More Suitable for Beginners vs. More Advanced Readers? Finance...
By Leonard Pokrovski 2025-10-08 20:56:28 0 2K
Business
What Skills Do Successful Startup Founders Have?
Starting a business and leading a startup is no easy feat. The path to success is often filled...
By Dacey Rankins 2025-04-01 16:20:01 0 6K
Искусство, культура и развлечения
Круэлла. Cruella. (2021)
Великобритания, 1960-е годы. Эстелла была необычным ребёнком, и особенно трудно ей было мириться...
By Nikolai Pokryshkin 2022-09-12 19:30:36 0 33K
Horror
The Shining. (1980)
A family heads to an isolated hotel for the winter where a sinister presence influences the...
By Leonard Pokrovski 2022-12-18 20:38:01 0 23K
Marketing and Advertising
How Is a Marketing Strategy Different from a Marketing Plan or Tactics?
Introduction Marketing is often described as both an art and a science, but one of the most...
By Dacey Rankins 2025-10-15 19:00:51 0 2K

BigMoney.VIP Powered by Hosting Pokrov