Built-in Functions for Manipulating Maps

There are a few built-in functions available to you when working with maps.

len()

len() returns the number of key-value pairs in a map. This value is always a number, and it is equal to the number of keys in the map.

>> len({1: 2, "a": 3})
// outputs 2

mapKeys()

mapKeys() returns all the keys of a map as elements of an array.

>> let my_map = {"name": "Bella", "age": 10, "gender": "female"}
>> mapKeys(my_map)
// outputs ['name', 'age', 'gender']

The order of elements in the array returned by mapKeys() is not guaranteed to be constant.

mapValues()

mapValues() returns all the values of a map as elements of an array.

>> let my_map = {"name": "Bella", "age": 10, "gender": "female"}
>> mapValues(my_map)
// outputs ['Bella', 10, 'female']

Like mapKeys(), the order of elements in the array returned by mapValues() is not guaranteed to be constant.

mapEntries()

mapEntries() returns an array whose elements are the key-value pairs of a map. Each element is represented as an array where the first element is the key and the second is the value of the pair. The returned array is a 2-dimensional array.

>> let my_map = {"name": "Bella", "age": 10, "gender": "female"}
>> mapEntries(my_map)
// outputs [['age', 10], ['gender', 'female'], ['name', 'Bella']]

Last updated