Maps - Javascript

  • var = new Map(varO/varA) => Initializing a map function, Giving an iterable object as parameter is optional
  • var.set(key, value) => Adds the key and value to the Map Object
  • var.has(key) => Returns a boolean value based on whether the specified key is present or not
  • var.get(key) => Returns the value of the corresponding key, if not present then undefined
  • var.delete(key) => Deletes both the key as well as a value from the map
  • var.clear() => This method will remove all the elements from the Map object
  • var.size => Returns the number of elements or the key-value pairs in the map
  • for(let [key, value] of var) {} => Can directly access key & value of map by for loop
  • for(let key of var.keys()) {} => Can directly access key of map by for loop
  • for(let value of var.value()) {} => Can directly access value of map by for loop
  • var.forEach((value, key) => {}) => Can directly access key & value of map by for loop
  • varA = Array.from(var) => Make an array from key & value pair of map
  • varA = Array.from(var.keys()) => Make an array from key pair of map
  • varA = Array.from(var.value()) => Make an array from value pair of map
Share: