SASS | Map Functions

The SASS Map data-type is used to display one or more key-value pairs. Along with the map functions shown in the below lists, you can also use any of the SASS list functions with maps as well.

The following lists contains all map functions in SASS:

  1. map-has-key($map, $key) function: This function returns a Boolean value that checks whether the given map contains the given key or not.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-has-key(("red": #ff0000, "yellow": #ffff00), blue)

      chevron_right

      
      

    • Output:
      false
  2. map-merge($map1, $map2) function: This function returns a map containing $map2 joined to the end of $map1.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-merge(("red": #ff0000, "yellow": #ffff00), ("blue": #0000ff)

      chevron_right

      
      

    • Output:
      ("red": #ff0000, "yellow": #ffff00, "blue": #0000ff)
  3. map-keys($map) function: This function returns the list of the keys in the given map.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-keys(("red": #ff0000, "yellow": #ffff00))

      chevron_right

      
      

    • Output:
      ("red", "yellow")
  4. map-remove($map, $keys) function: This function returns a map without the given keys.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-remove(("red": #ff0000, "yellow": #ffff00), "red")

      chevron_right

      
      

    • Output:
      ("yellow": #ffff00)
  5. map-values($map) function: This function returns the list of the values in the given map.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-values(("red": #ff0000, "yellow": #ffff00))

      chevron_right

      
      

    • Output:
      (#ff0000, #ffff00)
  6. map-get($map, $key) function: This function returns the value associated with the given key.
    • Example:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      map-get(("blue": #0000ff, "yellow": #ffff00), "blue")

      chevron_right

      
      

    • Output:
      #0000ff



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 :

1


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