List
Hierarchy
- List
Index
Constructors
Methods
Constructors
constructor
- new List(length: number, commaSeparator?: boolean): List
-
Creates a new Sass list.
The initial values of the list elements are undefined. These elements must be set using setValue before accessing them or passing the list back to Sass.
Example
constlist = newsass.types.List(3);
list.setValue(0, newsass.types.Number(10, "px"));
list.setValue(1, newsass.types.Number(15, "px"));
list.setValue(2, newsass.types.Number(32, "px"));
list; // 10px, 15px, 32pxParameters
-
length: number
The number of (initially undefined) elements in the list.
-
OptionalcommaSeparator: booleanIf
true, the list is comma-separated; otherwise, it's space-separated. Defaults totrue.
Returns List
-
Methods
getLength
- getLength(): number
-
Returns the number of elements in the list.
Example
// list is `10px, 15px, 32px`
list.getLength(); // 3
// list is `1px solid`
list.getLength(); // 2Returns number
getSeparator
- getSeparator(): boolean
-
Returns
trueif this list is comma-separated andfalseotherwise.Example
// list is `10px, 15px, 32px`
list.getSeparator(); // true
// list is `1px solid`
list.getSeparator(); // falseReturns boolean
getValue
- getValue(index: number): undefined | LegacyValue
-
Returns the element at
index, orundefinedif that value hasn't yet been set.Example
// list is `10px, 15px, 32px`
list.getValue(0); // 10px
list.getValue(2); // 32pxThrows
Errorifindexis less than 0 or greater than or equal to the number of elements in this list.Parameters
-
index: number
A (0-based) index into this list.
Returns undefined | LegacyValue
-
setSeparator
- setSeparator(isComma: boolean): void
-
Sets whether the list is comma-separated.
Parameters
-
isComma: boolean
trueto make the list comma-separated,falseotherwise.
Returns void
-
setValue
- setValue(index: number, value: LegacyValue): void
-
Sets the element at
indextovalue.Example
// list is `10px, 15px, 32px`
list.setValue(1, newsass.types.Number(18, "px"));
list; // 10px, 18px, 32pxThrows
Errorifindexis less than 0 or greater than or equal to the number of elements in this list.Parameters
-
index: number
A (0-based) index into this list.
-
value: LegacyValue
Returns void
-
© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/classes/types.List
Sass's list type.
This list type’s methods use 0-based indexing, even though within Sass lists use 1-based indexing. These methods also don’t support using negative numbers to index backwards from the end of the list.