Remove Key

 Maps - Remove Key

This Deluge task removes the specified key and associated value from the target map variable.

Syntax

<map-variable>.remove(<key-name>);

where,

<map-variable>  refers to the target map variable from which the key is to be removed
<key-name> is the key that is to be removed

Example

Consider the below example:

  • A map variable map1 is declared.
  • Key-value pairs: John-India and David-USA, are added in it.
  • The pair John-India is removed, and map1 is displayed using the info task.
map1 = map();
map1.put("John", "India");
map1.put("David", "USA");
map1.remove("John");
info map1;

Output will be {"David":"USA"}.