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
Personal Finance
What Options Do I Have If I Cannot Repay My Debts?
What Options Do I Have If I Cannot Repay My Debts? Falling behind on debt payments can be...
By Leonard Pokrovski 2025-10-29 18:34:44 0 4K
Nature and Science
My Neighbor Totoro. (1988)
When two girls move to the country to be near their ailing mother, they have adventures with the...
By Leonard Pokrovski 2023-03-15 17:30:45 0 29K
Marketing and Advertising
How Businesses Can Encourage Users to Generate Content: Turning Audiences into Advocates
Introduction In today’s digital landscape, User-Generated Content (UGC) is one of the most...
By Dacey Rankins 2025-11-06 18:58:32 0 7K
Sports and Hobbies
Exploring Hobbies for Kids and Teens: Cultivating Interests and Skills
In today’s fast-paced world, hobbies play a vital role in the development of children and...
By Dacey Rankins 2024-12-09 14:32:11 0 13K
Business
What Questions Should I Ask My Mentor?
A mentoring relationship is most effective when driven by meaningful dialogue and mutual...
By Dacey Rankins 2025-05-24 15:41:46 0 7K

BigMoney.VIP Powered by Hosting Pokrov