JavaScript Map

0
11K

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
Business
What Are Common Execution Pitfalls in Startups?
Launching a startup is an exciting journey, but it’s also filled with hidden challenges...
By Dacey Rankins 2025-04-30 12:54:47 0 9K
Спорт
Семь самураев. Seven Samurai. (1954)
Япония, XVI век. В стране полыхает гражданская война, повсюду орудуют банды разбойников и...
By Nikolai Pokryshkin 2022-11-15 17:46:10 0 31K
Science Fiction and Fantasy
The Super Mario Bros. Movie. (2023)
A plumber named Mario travels through an underground labyrinth with his brother, Luigi, trying to...
By Leonard Pokrovski 2023-06-11 14:29:44 0 30K
Business
What Are the Basic Types of Communication Skills? (Verbal, Written, Non-Verbal, Listening)
Introduction Communication is the foundation of human interaction. Every conversation, message,...
By Dacey Rankins 2025-11-20 15:14:33 0 534
News
What Leadership Qualities Does the CEO Possess?
A CEO's leadership qualities are among the most defining elements of their effectiveness. Great...
By Dacey Rankins 2025-06-30 14:07:06 0 7K

BigMoney.VIP Powered by Hosting Pokrov