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.

Zoeken
Categorieën
Read More
Decision Making and Problem Solving
How do students develop creative thinking?
How Do Students Develop Creative Thinking? Creativity Often Begins Where Certainty Ends A...
By Michael Pokrovski 2026-06-11 19:53:05 0 8K
Economics
Can Capitalism Exist with Social Welfare Programs?
Can Capitalism Exist with Social Welfare Programs? Capitalism and social welfare are often...
By Leonard Pokrovski 2026-02-12 22:13:08 0 24K
Personal Finance
Which Type of Loan Should I Choose?
Which Type of Loan Should I Choose? Understanding Your Options and Finding the Best Loan for...
By Leonard Pokrovski 2025-11-07 23:35:21 0 10K
Business
What Influences Consumer Decisions?
A woman stands frozen in the cereal aisle holding two nearly identical boxes. One costs $4.99....
By Dacey Rankins 2026-05-26 17:07:53 0 5K
Productivity
What is habit stacking?
What Is Habit Stacking? Habit stacking is a method of building new behaviors by attaching them...
By Michael Pokrovski 2026-05-21 17:44:28 0 1K

BigMoney.VIP Powered by Hosting Pokrov