In Sass, the map data type represents one or more key/value pairs.
It is also possible to use the List functions from the previous page, with maps. Then the map will be treated as a list with two elements.
nth(("red": #ff0000, "green": #00ff00), 2) //returns ("green" #00ff00)
Sass maps are immutable (they cannot change). So, the map functions that return a map, will return a new map, and not change the original map.
The following table lists all map functions in Sass:
Function | Description | Examples |
---|---|---|
map-get($map, $key) | Returns the value associated with the specified key | map-get(("red": #ff0000, "green": #00ff00), "green")
Result: #00ff00 |
map-merge($map1, $map2) | Returns a map containing $map2 appended to the end of $map1 | map-merge(("red": #ff0000, "green": #00ff00), ("blue": #0000ff)
Result: ("red": #ff0000, "green": #00ff00, "blue": #0000ff) |
map-remove($map, $keys) | Returns a map without the specified keys | map-remove(("red": #ff0000, "green": #00ff00), "red")
Result: ("green": #00ff00) |
map-keys($map) | Returns a list of the keys in the specified map | map-keys(("red": #ff0000, "green": #00ff00))
Result: ("red", "green") |
map-values($map) | Returns a list of the values in the specified map | map-values(("red": #ff0000, "green": #00ff00))
Result: (#ff0000, #00ff00) |
map-has-key($map, $key) | Returns a Boolean value indicating whether the specified map contains the specified key | map-has-key(("red": #ff0000, "green": #00ff00), blue)
Result: false |