Skip to content
Related Articles

Related Articles

Improve Article

Sass | sass:map module

  • Last Updated : 16 Jul, 2020

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 the given key in the map. In case, no value is associated then it returns null.
    Syntax:




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

    Example:




    $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:






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

    Example:




    $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:




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

    Example:




    $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 overrwrite 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:




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

    Example:




    $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:




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

    Example:




    $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:




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

    Example:




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

    Output:

    5 3 13
    



My Personal Notes arrow_drop_up
Recommended Articles
Page :