JavaScript Map

0
12Кб

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.

Поиск
Категории
Больше
Business
What Are the Main Causes of Conflict?
Conflicts can arise due to personality differences, miscommunication, competition for resources,...
От Dacey Rankins 2025-06-04 14:18:35 0 7Кб
Science in Society
Science in Society: Bridging Knowledge and Progress
Science is more than just a field of study—it is a cornerstone of modern society, shaping...
От Dacey Rankins 2024-11-15 14:54:33 0 13Кб
Programming
Gitbook
What Is GitBook? GitBook is a collaborative documentation tool that allows anyone to...
От Jesse Thomas 2023-07-06 20:25:06 0 14Кб
Programming
Build a 2D game with Python
Python is an outstanding language for people learning to program, and perfect for anyone...
От Jesse Thomas 2023-06-30 21:26:00 0 15Кб
Business
How to Find and Where to Use Competitors' Databases: A Full Review
When the competition in the niche becomes very high, it becomes difficult to find new customers....
От Dacey Rankins 2024-09-05 18:16:06 0 12Кб

BigMoney.VIP Powered by Hosting Pokrov