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.

Pesquisar
Categorias
Leia Mais
Mental Health
Psychosis: Culture
Cross-cultural studies into schizophrenia have found that individual experiences of psychosis and...
Por Kelsey Rodriguez 2023-06-09 20:02:28 0 11K
Personal Finance
How Much Should I Save Each Month?
How Much Should I Save Each Month? Understanding the 20% Rule—and How to Know What’s...
Por Leonard Pokrovski 2025-12-03 17:02:58 0 1K
Социальные проблемы
Рай и ад. High and Low. (1963)
Преуспевающий бизнесмен должен решить для себя, заплатит ли он выкуп похитителям, которые по...
Por Nikolai Pokryshkin 2023-01-08 22:19:53 0 22K
Personal Finance
How Much Should I Have in an Emergency Fund? 3 Months or 6 Months? How Big Should My Emergency Fund Be?
How Much Should I Have in an Emergency Fund? 3 Months or 6 Months? How Big Should My Emergency...
Por Leonard Pokrovski 2025-12-03 17:08:28 0 2K
Ужасы
Головокружение. Vertigo. (1958)
Скотти Фергюсон - отставной сыщик, которого не назовешь баловнем судьбы: одинокий, оставшийся за...
Por Nikolai Pokryshkin 2023-01-17 10:22:33 0 31K

BigMoney.VIP Powered by Hosting Pokrov