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.

Site içinde arama yapın
Kategoriler
Read More
Photography
Photography: A Journey Through Time
Photography, an art and science that captures moments in time, has undergone remarkable...
By Dacey Rankins 2024-10-09 16:56:05 0 17K
Marketing and Advertising
What Is Dynamic Search Advertising (DSA)?
Dynamic Search Advertising (DSA) is a powerful search engine marketing (SEM) feature that...
By Dacey Rankins 2026-02-19 17:32:00 0 2K
Business
What Role Does Customer Development Play in Startup Innovation?
In the fast-paced and competitive world of startups, innovation is key to staying relevant and...
By Dacey Rankins 2025-03-21 14:11:02 0 12K
Programming
Python Dictionary Key/Value Swap
You can change the keys and values in a dictionary using a loop and items(). This can be helpful...
By Jesse Thomas 2023-03-03 21:55:48 0 13K
Marketing and Advertising
What Are Some Great Content Marketing Tools?
A Complete Guide to Essential Platforms for Strategy, Creation, and Optimization Content...
By Dacey Rankins 2025-09-29 20:25:47 0 7K

BigMoney.VIP Powered by Hosting Pokrov