JavaScript Map

0
12KB

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.

Rechercher
Catégories
Lire la suite
Business
Describe a Challenging Situation You've Faced and How You Handled It
Employers Look for Problem-Solving Skills and Resilience One of the most telling questions in an...
Par Dacey Rankins 2025-06-18 14:54:01 0 13KB
Rural Living
Life in the city and in the village: Pros and cons of the city and village
What is better than a town or village? There is no definitive answer to this question. At least,...
Par FWhoop Xelqua 2023-02-02 16:26:24 0 25KB
Marketing and Advertising
What Is Guerrilla Marketing? Definition, Core Principles, and Modern Applications
Introduction Marketing has always been about grabbing attention — but in today’s...
Par Dacey Rankins 2025-10-07 14:54:22 0 7KB
Marketing and Advertising
How to Measure the Success of a Video Marketing Campaign
1. Introduction: Why Measuring Matters Video marketing has become one of the most effective ways...
Par Dacey Rankins 2025-11-12 16:02:40 0 5KB
Business
How Do PMs Work With Customers, Stakeholders, and Engineering Teams?
The role of a product manager (PM) can often seem ambiguous to those outside the field. Unlike...
Par Dacey Rankins 2025-08-18 13:27:56 0 8KB

BigMoney.VIP Powered by Hosting Pokrov