Javascript Map delete()

Introduction

The Javascript Map delete() method removes the element from a Map object by key.

myMap.delete(key);
  • key - the key of the element to remove from the Map object.

It returns true if an element in the Map object existed and has been removed.

It returns false if the element does not exist.

var myMap = new Map();
myMap.set('bar', 'foo');
console.log(myMap);/*from   ww  w  . j  a  v a2  s  . c o  m*/

const b = myMap.delete('bar'); 
console.log(b);
console.log(myMap);
console.log(myMap.has('bar'));



PreviousNext

Related