Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

What is the map.remove() method in Dart?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The map.remove() function in Dart removes a specific element (key-value pair) from the map.

  • If the key is found in the map, the key-value pair is removed and the key is returned.
  • If the key is not found in the map, null is returned.

The illustration below shows the visual representation of the map.remove() function:

Figure 1: Visual representation of map.remove() function

Syntax

map_name.remove(key)

map_name is the name of the queue.

Parameter

The map.remove() function requires a key to remove that specific key-value pair from the map.

Return value

The Dart function map.remove() removes a specific element (key-value pair) from a map.

Code

The following code shows how to use the map.remove() function in Dart:

import 'dart:convert';
void main() {
var map = new Map();
map [1] = 'Tom';
map [2] = 'Alsvin';
map [3] = 'Eddie';
//map containg key value pairs before remove
print("map elements before remove: ${map}");
//map after remove 3rd element
print("The value against 3rd element: ${map.remove(3)}");
print("map elements after remove: ${map}");
}

RELATED TAGS

dart
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring