JavaScript Map

0
12KB

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.

Rechercher
Catégories
Lire la suite
Horror
The Evolution of the Horror Movie Industry: A Tale of Fear, Innovation, and Endurance
The horror movie industry is one of the most enduring and versatile genres in cinema history....
Par Dacey Rankins 2024-11-19 15:41:43 0 14KB
Business
What Type of Business Should I Start?
Starting a business is an exciting venture, but choosing the right type can feel overwhelming....
Par Dacey Rankins 2025-02-06 15:01:46 0 11KB
Business
What Are the Benefits and Risks of Entrepreneurship?
Entrepreneurship is an exciting journey that offers financial independence, creativity, and the...
Par Dacey Rankins 2025-03-12 14:41:16 0 11KB
Financial Services
The Phillips curve in the Keynesian perspective
Key points A Phillips curve shows the tradeoff between unemployment and inflation...
Par Mark Lorenzo 2023-06-21 18:14:23 0 12KB
Financial Services
Explicit and implicit costs and accounting and economic profit
Key points Privately owned firms are motivated to earn profits. Profit is the...
Par Mark Lorenzo 2023-02-23 18:34:44 0 16KB

BigMoney.VIP Powered by Hosting Pokrov