Yahoo India Web Search

Search results

  1. Aug 22, 2013 · Learn how JavaScript objects, maps and weak maps can be used as hash maps, and how they differ in performance, ordering and key types. See answers from experts and users with examples and references.

  2. Learn how to create and use a Map, a data structure that holds key-value pairs and remembers the insertion order. Compare Maps with Objects and see browser support for Map.

  3. Nov 8, 2023 · Learn how to create, manipulate, and optimize HashMaps in JavaScript using the built-in Map object. Explore the basics, practical use cases, advanced techniques, and real-world applications of this data structure.

    • Overview
    • Description
    • Static properties
    • Static methods
    • Instance properties
    • Instance methods
    • Examples

    The Map 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.

    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).

    Map[@@species]

    The constructor function that is used to create derived objects.

    Map.groupBy()

    Groups the elements of a given iterable using the values returned by a provided callback function. The final returned Map uses the unique values from the test function as keys, which can be used to get the array of elements in each group.

    These properties are defined on Map.prototype and shared by all Map instances.

    Map.prototype.constructor

    The constructor function that created the instance object. For Map instances, the initial value is the Map constructor.

    Map.prototype.size

    Returns the number of key/value pairs in the Map object.

    Map.prototype[@@toStringTag]

    Map.prototype.clear()

    Removes all key-value pairs from the Map object.

    Map.prototype.delete()

    Returns true if an element in the Map object existed and has been removed, or false if the element does not exist. map.has(key) will return false afterwards.

    Map.prototype.entries()

    Returns a new Iterator object that contains a two-member array of [key, value] for each element in the Map object in insertion order.

    Using the Map object Using NaN as Map keys

    NaN can also be used as a key. Even though every NaN is not equal to itself (NaN !== NaN is true), the following example works because NaNs are indistinguishable from each other:

    Iterating Map with for...of

    Maps can be iterated using a for...of loop:

    Iterating Map with forEach()

    Maps can be iterated using the forEach() method:

  4. 1 day ago · Learn how to create and use a map object in JavaScript, a collection of key-value pairs that enables efficient data retrieval and manipulation. See examples of map methods, advantages, and supported browsers.

    • 4 min
  5. Apr 23, 2024 · Learn how to use hashmaps in JavaScript to store and retrieve key-value pairs efficiently. Explore the properties, methods, and implementation of hashmaps using objects or the Map object.

  6. People also ask

  7. Dec 17, 2014 · JavaScript objects can be accessed in a number of ways. Let's take this object as an example: var person = { first_name: "John", last_name: "Smith", age: 39 };