Map.size
is a property of a map in TypeScript. It is used to find out the total number of entries in a map. It returns an integer value.
Map.size
Map
: This is the map whose total size we want to know.
The value returned is an integer that is the number of elements the map contains.
// Create some mapslet oddNumbers = new Map<string, number>([["one", 1], ["three", 3], ["five", 5]])let products = new Map<string, number>([["rice", 500], ["bag", 10]])let countries = new Map<string, string>([["NG", "Nigeria"], ["BR", "Brazil"], ["IN", "India"]])let isOld = new Map<string, boolean>([["James", false], ["Jane", true], ["Doe", false]])let nullishMap = new Map<null, null>()// get the sizesconsole.log(oddNumbers.size)console.log(products.size)console.log(countries.size)console.log(isOld.size)console.log(nullishMap.size)
size
property, we get the size of each map and print the value to the console.