Open In App

Sass | sass:map module

Last Updated : 11 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The sass:map module gives functions that makes it possible to look up the values associated with the key of a map. Some of the major functions are listed below:

  • map.get(): This function returns the value associated with the given key in the map. In case, no value is associated then it returns null. Syntax: 

css




map.get(map, key)
map-get(map, key)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3, "geeksforgeeks": 13)
 
@debug map.get($gfg, "geeks") 
@debug map.get($gfg, "GFG") 


  • Output:
5
null
  • map.has-key(): This function returns weather any value is associated with the given key in the map or not. It returns true or false. Syntax: 

css




map.has-key(map, key)
map-has-key(map, key)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3, "geeksforgeeks": 13)
 
@debug map.has-key($gfg, "geeks") 
@debug map.has-key($gfg, "GFG") 


  • Output:
true
false
  • map.keys(): This function returns a comma-separated list of all the keys in the map. Syntax: 

css




map.keys(map)
map-keys(map)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3, "geeksforgeeks": 13)
 
@debug map.keys($gfg)


  • Output:
"geeks", "for", "geeksforgeeks"
  • map.merge(): This function returns a new map with all the keys and value of both the given maps included. The function can also be used to add a new value or overwrite a value in one map, by passing a single key/value pair as second map. If both maps have the same key, second map’s value takes precedence. All keys in the returned map that also appear in first map have the same order as they are. New keys from second map appear at the end of the map. Syntax: 

css




map.merge(map1, map2)
map-merge(map1, map2)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3);
$slash: ("geeksforgeeks": 13);
 
@debug map.merge($gfg, $slash);
 
@debug map.merge($gfg, ("geeksforgeeks": 20));
 
@debug map.merge($gfg, ("geeks": 20));


  • Output:
"geeks": 5, "for": 3, "geeksforgeeks":13
"geeks": 5, "for": 3, "geeksforgeeks":20
"geeks": 20, "for":3
  • map.remove(): This function returns a copy of the given map without the keys and associated value called in the function. Keys are ignored if no such key exist in the map. Syntax: 

css




map.remove(map, keys)
map-remove(map, keys)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3, "geeksforgeeks": 13)
 
@debug map.remove($gfg, "geeks")
@debug map.remove($gfg, "geeks", "for")
@debug map.remove($gfg, "geek") 


  • Output:
"for": 3, "geeksforgeeks":13
"geeks": 5, "geeksforgeeks":13"
geeks": 5, "for": 3, "geeksforgeeks":13
  • map.values(): This function returns a comma-separated list of all the values of the map. Syntax: 

css




map.values(map)
map-values(map)


  • Example: 

css




$gfg: ("geeks": 5, "for": 3, "geeksforgeeks": 13)
 
@debug map.remove($gfg) 


  • Output:
5 3 13


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads