Sass Lijst Functies

Sass Lijst Functies

List functions are used to access values in the list, combine lists, and add items to the list.

Sass lists are immutable (they cannot be changed). Therefore, list functions that return a list return a new list without changing the original list.

Sass lists are based on 1. The first list item in the list is at index 1, not 0.

The following lists all list functions in Sass:

Function Description & example
append(lijst, waarde, [separator])

Adds a single value to the end of the list.
The separator can be auto, comma or space. auto is the default value.

Voorbeeld:

append((a b c), d)

Result: a b c d

append((a b c), (d), comma)

Result: a, b, c, d

index(lijst, waarde)

Returns the index position of the value in the list.

Voorbeeld:

index(a b c, b)

Result: 2

index(a b c, f)

Result: null

is-bracketed(lijst)

Check if the list has brackets.

Voorbeeld:

is-bracketed([a b c])

Result: true

is-bracketed(a b c)

Result: false

join(list1, list2, [separator, bracketed)

The list2 added to list1 at the end.
The separator can be auto, comma or space.
auto is the default value (the separator from the first list will be used).
bracketed Can be auto, true or false. auto is the default value.

Voorbeeld:

join(a b c, d e f)

Result: a b c d e f

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

Result: a, b, c, d, e, f

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

Resultaat: [a b c d e f]

length(lijst)

Geef de lengte van de lijst terug.

Voorbeeld:

length(a b c)

Resultaat: 3

list-separator(lijst)

Geef de gebruikte lijstseparator terug als string. Dit kan space of comma zijn.

Voorbeeld:

list-separator(a b c)

Resultaat: "space"

list-separator(a, b, c)

Resultaat: "comma"

nth(lijst, n)

Geef het n-de element van de lijst terug.

Voorbeeld:

nth(a b c, 3)

Resultaat: c

set-nth(lijst, n, waarde)

Stel de n-de element van de lijst in op de opgegeven waarde.

Voorbeeld:

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

Resultaat: a x c

zip(lijsten)

Combineer lijsten tot een enkele multidimensionale lijst.

Voorbeeld:

zip(1px 2px 3px, solide gebroken gepunt, rood groen blauw)

Resultaat: 1px solide rood, 2px gebroken groen, 3px gepunkt blauw