Sass | sass:map module

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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:



    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    $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));

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    5 3 13
    



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.