JavaScript Map

0
13KB

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.

Suche
Kategorien
Mehr lesen
Decision Making and Problem Solving
Can creativity be learned?
Can Creativity Be Learned? The Question That Assumes the Wrong Thing There is a quiet...
Von Michael Pokrovski 2026-06-11 12:54:01 0 4KB
Business
What Strategies Can Solopreneurs Use to Market Their Business?
Marketing is one of the most critical components of a successful business, yet it can often feel...
Von Dacey Rankins 2025-02-13 16:20:46 0 12KB
Decision Making and Problem Solving
How do I stop negative thinking?
You sit staring at a cascading series of worst-case scenarios playing out in your mind, feeling...
Von Michael Pokrovski 2026-07-24 10:19:55 0 605
Finance
How Long Does It Take to Read Finance Biographies?
How Long Does It Take to Read Finance Biographies? A Look at Why They’re So Dense —...
Von Leonard Pokrovski 2025-10-08 20:59:04 0 14KB
Business
What ethical practices should I follow as a content creator?
As a content creator, you have a unique influence over your audience, and with that influence...
Von Dacey Rankins 2025-02-21 15:17:02 0 12KB

BigMoney.VIP Powered by Hosting Pokrov