Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Sass List Functions

Sass List Functions

Sass Functions Sass Functions

Sass list functions are used to process lists, allowing access to values in a list, adding elements to a list, merging lists, and more.

Sass lists are immutable, so when processing a list, a new list is returned rather than modifying the original list.

The starting index of a list is 1, remember it is not 0.

The following table lists Sass's list functions:

function Description & Examples
append(list, value, [separator]) Append a single value value to the end of the list.separator is the separator, which is auto-detected by default, or can be specified as a comma or space.
 **实例:        

**append((a b c), d)
Result: a b c d
append((a b c), (d), comma)
Result: a, b, c, d | | index(list, value) | Return the element value 's index position in the list.

 **实例:**       

 index(a b c, b)       

 结果: 2       

 index(a b c, f)       

 结果: null |

| is-bracketed(list) | Determine whether the list has square brackets

 **实例:**       

 is-bracketed([a b c])       

 结果: true       

 is-bracketed(a b c)       

 结果: false |

| join(list1, list2, [separator, bracketed]) | Merge two lists, appending list list2 to list list1 end of theseparator is the separator, which is auto-detected by default, or can be specified as a comma or space. bracketed Square brackets are auto-detected by default and can be set to true or false.

 **实例:**       

 join(a b c, d e f)       

 结果: a b c d e f       

 join((a b c), (d e f), comma)       

 结果: a, b, c, d, e, f       

 join(a b c, d e f, $bracketed: true)       

 结果: [a b c d e f] |

| length(list) | Return the length of the list

 **实例:**       

 length(a b c)       

 结果: 3 |

| list-separator(list) | Return the separator type of a list. It can be a space or a comma.

 **实例:**       

 list-separator(a b c)       

 结果: "space"       

 list-separator(a, b, c)       

 结果: "comma" |

| nth(list, n) | Get the n th item's value.

 **实例:**       

 nth(a b c, 3)       

 结果: c |

| set-nth(list, n, value) | Set the list's n th item's value to value.

 **实例:**       

 set-nth(a b c, 2, x)       

 结果: a x c |

| zip(lists) | Re-group multiple lists by the same index value into a new multi-dimensional list.

 **实例:**       

 zip(1px 2px 3px, solid dashed dotted, red green blue)       

 结果: 1px solid red, 2px dashed green, 3px dotted blue |


Sass Functions Sass Functions