19.15 Conflicting Languages. This Agreement is made in the Indonesian and the English language, and both versions are equally authentic. In the event of any inconsistency or different interpretation between the Indonesian version and the English version, the parties agree to amend the Indonesian version to make the relevant part of the Indonesian version consistent with the relevant part of the English version. Show The 1 object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value. 1 objects are collections of key-value pairs. A key in the 1 may only occur once; it is unique in the 1's collection. A 1 object is iterated by key-value pairs — a 6 loop returns a 2-member array of 7 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 8 method (that is, there wasn't a key with the same value already in the map when 8 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). Value equality is based on the algorithm. (It used to use , which treated 0 and 1 as different. Check .) This means 2 is considered the same as 2 (even though 4) and all other values are considered equal according to the semantics of the 5 operator. 6 is similar to 1—both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. For this reason (and because there were no built-in alternatives), 6 has been used as 1 historically.However, there are important differences that make 1 preferable in some cases: 1 does not contain any keys by default. It only contains what is explicitly put into it.An 6 has a prototype, so it contains default keys that could collide with your own keys if you're not careful.Note: This can be bypassed by using 3, but this is seldom done.SecurityA 1 is safe to use with user-provided keys and values.Setting user-provided key-value pairs on an 6 may allow an attacker to override the object's prototype, which can lead to object injection attacks . Like the accidental keys issue, this can also be mitigated by using a 6-prototype object.Key TypesA 1's keys can be any value (including functions, objects, or any primitive).The keys of an 6 must be either a 9 or a 0.Key OrderThe keys in 1 are ordered in a simple, straightforward way: A 1 object iterates entries, keys, and values in the order of entry insertion.Although the keys of an ordinary 6 are ordered now, this was not always the case, and the order is complex. As a result, it's best not to rely on property order.The order was first defined for own properties only in ECMAScript 2015; ECMAScript 2020 defines order for inherited properties as well. See the and abstract specification operations. But note that no single mechanism iterates all of an object's properties; the various mechanisms each include different subsets of properties. ( 4 includes only enumerable string-keyed properties; 5 includes only own, enumerable, string-keyed properties; 6 includes own, string-keyed properties even if non-enumerable; 7 does the same for just 0-keyed properties, etc.)Size The number of items in a 1 is easily retrieved from its 0 property.Determining the number of items in an 6 is more roundabout and less efficient. A common way to do it is through the 2 of the array returned from 3.IterationA 1 is an iterable, so it can be directly iterated. 6 does not implement an , and so objects are not directly iterable using the JavaScript for...of statement (by default).Note:
Performs better in scenarios involving frequent additions and removals of key-value pairs. Not optimized for frequent additions and removals of key-value pairs. Serialization and parsingNo native support for serialization or parsing. (But you can build your own serialization and parsing support for 1 by using 9 with its replacer argument, and by using 0 with its reviver argument. See the Stack Overflow question How do you JSON.stringify an ES6 Map?).Native support for serialization from 6 to JSON, using 9.Native support for parsing from JSON to 6, using 0.Setting Object properties works for Map objects as well, and can cause considerable confusion. Therefore, this appears to work in a way:
But that way of setting a property does not interact with the Map data structure. It uses the feature of the generic object. The value of 'bla' is not stored in the Map for queries. Other operations on the data fail:
The correct usage for storing data in the Map is through the 5 method.
6Creates a new 1 object. 8The constructor function that is used to create derived objects. 9The initial value of the 0 property is the string 1. This property is used in 2. 3Returns the number of key/value pairs in the 1 object. 5Removes all key-value pairs from the 1 object. 7Returns 8 if an element in the 1 object existed and has been removed, or 0 if the element does not exist. 1 will return 0 afterwards. 3Returns the value associated to the passed key, or 4 if there is none. 5Returns a boolean indicating whether a value has been associated with the passed key in the 1 object or not. 7Sets the value for the passed key in the 1 object. Returns the 1 object. 0Returns a new Iterator object that contains a two-member array of 7 for each element in the 1 object in insertion order. 3Returns a new Iterator object that contains the keys for each element in the 1 object in insertion order. 5Returns a new Iterator object that contains the values for each element in the 1 object in insertion order. 7Returns a new Iterator object that contains a two-member array of 7 for each element in the 1 object in insertion order. 00Calls 01 once for each key-value pair present in the 1 object, in insertion order. If a 03 parameter is provided to 04, it will be used as the 05 value for each callback.
2 can also be used as a key. Even though every 2 is not equal to itself ( 4 is true), the following example works because 2s are indistinguishable from each other: |