JavaScript Map

0
12Кб

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.

Поиск
Категории
Больше
Social Issues
Trainspotting. (1996)
Renton, deeply immersed in the Edinburgh drug scene, tries to clean up and get out, despite the...
От Leonard Pokrovski 2023-03-10 19:45:23 0 21Кб
Другое
Pirates of the Caribbean: The Curse of the Black Pearl (2003)
Blacksmith Will Turner teams up with eccentric pirate "Captain" Jack Sparrow to save his love,...
От Leonard Pokrovski 2023-06-23 19:53:50 0 33Кб
Personal Finance
What Happens If You Owe Taxes — And Can You Set Up a Payment Plan?
What Happens If You Owe Taxes — And Can You Set Up a Payment Plan? Finding out you owe...
От Leonard Pokrovski 2025-11-21 19:51:01 0 2Кб
Business
How to Attract and Retain Top Talent in a Startup Environment
In the fast-paced, competitive world of startups, one of the most critical factors for success is...
От Dacey Rankins 2025-05-06 12:48:30 0 11Кб
Business
How Do Project Managers Handle Risks?
Effective risk management is one of the most critical responsibilities of a project manager....
От Dacey Rankins 2025-05-16 14:33:48 0 11Кб

BigMoney.VIP Powered by Hosting Pokrov