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.

Site içinde arama yapın
Kategoriler
Read More
Business
How Would You Describe the Company Culture?
Company culture is more than a buzzword—it’s the foundation that shapes how employees...
By Dacey Rankins 2025-08-09 18:27:40 0 10K
Decision Making and Problem Solving
What is confirmation bias?
What Is Confirmation Bias? The Mind's Quiet Preference for Agreement Imagine two people reading...
By Michael Pokrovski 2026-06-09 05:17:37 0 1K
Business
How Much Does It Cost to Build an On-Demand Platform?
A founder once asked me what sounded like a straightforward question: "How much will it cost to...
By Dacey Rankins 2026-06-30 21:41:03 0 317
Marketing and Advertising
Why Are Advertising Biographies Important to Study?
Advertising is often studied through campaigns, platforms, metrics, and strategies. While these...
By Dacey Rankins 2026-01-09 20:00:06 0 7K
Business
How Do Growth Patterns Differ (Linear vs Exponential)?
When we talk about growth, we often assume it’s just “more” over time. But the...
By Dacey Rankins 2025-09-09 14:29:27 0 8K

BigMoney.VIP Powered by Hosting Pokrov