JavaScript Map

0
12K

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
Business
What Advice Would You Give to Aspiring Leaders?
Leadership is not a destination—it’s a continuous journey of growth, learning, and...
By Dacey Rankins 2025-05-09 15:09:29 0 7K
Business
What Are Effective Marketing Strategies for Startups?
Marketing is one of the most important components of growing a successful startup. For many...
By Dacey Rankins 2025-03-05 16:30:38 0 11K
Business
You Can’t Hack the Growth of Just Anything: Why Growth Hacking Requires Product/Market Fit First
One of the most common misconceptions about growth hacking is that it can be applied to any...
By Dacey Rankins 2025-09-12 20:03:33 0 3K
Business
Which Books or Media Detail This CEO’s Biography?
The best way to understand a CEO’s philosophy, achievements, and challenges is often...
By Dacey Rankins 2025-08-14 21:39:13 0 5K
Marketing and Advertising
What Makes a Good PR Agency — and How to Choose a PR Firm That Fits Your Brand
Introduction: The Power of the Right PR Partner In today’s fast-moving, reputation-driven...
By Dacey Rankins 2025-10-27 17:24:16 0 2K

BigMoney.VIP Powered by Hosting Pokrov