The map.length
function in Dart returns the number of elements (key-value pairs) in the map. In short, this function is used to get the current size of the map.
Figure 1 shows the visual representation of the map.length
function:
int map_name.length
// where the map_name is the name of the map
This function does not require a parameter.
This function returns the number of elements in the map and is used to get the current size of the map.
The following code shows how to use map.length
function in Dart:
import 'dart:convert';void main() {var map_1 = new Map();map_1 [1] = 'Tom';map_1 [2] = 'Alsvin';map_1 [3] = 'Eddie';//map containg key value pairsprint("map_1 length: ${map_1.length}");//map emptyvar map_2 = new Map();print("map_2 length: ${map_2.length}");}