SASS provides many built-in modules that contain various useful functions and some mixins that makes it easy to use. All built-in modules begin with sass: to show that they are different from other modules and a part of SASS itself. One of the built-in modules is the sass:list module that makes it possible to access and modify values in a list.
Note: In Sass, each map counts as a list containing two elements for each key/value pair. For example, (1: 2, 3: 4) counts as (1 2, 3 4). So all the below discussed functions work for maps as well as lists. This module lets you access and modify lists.
The following methods are available in the sass:list module:
- list.append(): This function returns a copy of list with the given value added to the end.
Syntax:
list.append($list, $val, $separator:auto)append($list, $val, $separator:auto)chevron_rightfilter_noneIf the separator is a
comma, then the list returned will be comma-separated, and the same goes for space-separated. In case the separator isauto(default separator), the returned list will use the same separator as used by the list (or space if the list doesn’t have a separator). No other value is allowed in the separator. Unlike list.join(), if the value is a list, then it is nested within the returned list rather than adding each element to the returned list.
Example:
@debug list.append(10px20px,30px);@debug list.append((geeks, for), geeks);@debug list.append(10px20px,30px40px);@debug list.append(10px,20px, $separator: comma);@debug list.append((geeks, for), geeks, $separator: space);chevron_rightfilter_noneOutput:
10px 20px 30px geeks, for, geeks 10px 20px (30px 40px) 10px, 20px geeks for geeks
- list.index(): This function returns the index of a value in the list.
Syntax:
list.index($list, $value)index($list, $value)chevron_rightfilter_noneIn case the value does not appear in the list, the function returns
null. If the value appears multiple times in the list, the function returns the index of the first appearance of the value.Example:
@debug list.index(geeks for geeks, geeks);@debug list.index(geeks for geeks, for);@debug list.index(geeks for geeks, slash_it);chevron_rightfilter_noneOutput:
1 2 null
- list.join(): This function returns a new list which has the elements of
list1followed by the elements oflist2.Syntax:
list.join($list1, $list2,$separator:auto, $bracketed:auto)join($list1, $list2,$separator:auto, $bracketed:auto)chevron_rightfilter_noneIf the separator is
comma, then the list returned will be comma-separated, and same goes for space-separated. In case ofauto(default separator), the returned list will use the same separator as used by thelist1, if it has a separator orlist2if it has a separator, or else space as the separator. No other value is allowed in the separator. If bracketed is set to true, then the returned list consists of square brackets. Otherwise, the returned list does not have any brackets. If it isauto(default), then the returned list will be bracketed. No other values are allowed.
Example:
@debug list.join(10px20px,30px40px);@debug list.join((geeks, for), (geeks, gfg));@debug list.join(10px,20px);@debug list.join(10px,20px, $separator: comma);@debug list.join((geeks, for),(geeks, gfg), $separator: space);@debug list.join([10px],20px);@debug list.join(10px,20px, $bracketed: true);chevron_rightfilter_noneOutput:
10px 20px 30px 40px geeks, for, geeks, gfg 10px 20px 10px, 20px geeks for geeks gfg [10px 20px] [10px 20px]
- list.length(): This function returns the length of the list.
Syntax:
list.length($list)length($list)chevron_rightfilter_noneThis function can also be used to return the number of pairs in a map.
Example:
@debug list.length(geeks);@debug list.length(geeks for geeks);@debug list.length((gfg: geeksforgeeks,slash_it: Shivam));chevron_rightfilter_noneOutput:
1 3 2
- list.nth(): This function returns the element of the list present at index “n”.
Syntax:
list.nth($list, $n)nth($list, $n)chevron_rightfilter_noneIf
nis a non-positive integer, this function counts from the end of list. It throws an error if no element is present at indexn.Example:
@debug list.nth(geeks for geeks,2);@debug list.nth([geeks for geeks],3);chevron_rightfilter_noneOutput:
for geeks
- Sass sass:color Module
- Sass | sass:map module
- SASS sass:string Module
- How to create optional arguments for a SASS mixin?
- Sass @function Rule
- CSS Preprocessor | SASS
- How to calculate percent minus px in SASS ?
- SASS | Comments
- SASS | Variables
- SASS | @import
- SASS | Nesting
- SASS | Interpolation
- SASS | Placeholder Selectors
- SASS | Parent Selector
- SASS | @mixin and @include
- SASS | @if and @else
- SASS | Booleans and Boolean operators
- SASS | Shadowing and Flow Control
- Last-child and last-of-type selector in SASS
- What is the difference between Compass and SASS ?
Recommended Posts:
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.

