list.nth()
The list.nth() function returns the element of $list at index $n and/or with elements of given indexes $nts....
// Sass.
@use 'sass:list';
// The `list.nth()` function.
@function nth($list, $n, $nts...) {
$result: ();
@each $n in list.join($n, $nts, comma) {
@if $n and $n != 0 {
$result: list.append(
$result,
if(
list.length($list) >= if($n < 0, calc($n * -1), $n),
list.nth($list, $n),
null
),
list.separator($list)
);
}
}
@return if(list.length($nts) > 0, $result, list.nth($result, 1));
}https://github.com/angular-package/sass/blob/main/list/_list.nth.function.scss
Parameters
$list
$list A list from which the element of index $n and/or multiple indexes $nts are retrieved.
$n
$nThe required index of $list.
$nts...
$nts...Optional multiple indexes of $list.
Return
The return value is a retrieved element or list of retrieved elements.
Examples
Last updated
Was this helpful?