list.insert-nth()

The insert-nth() function returns the $list with $value inserted into index $n.

// Sass.
@use 'sass:list';

// The `list.insert-nth()` function.
@function insert-nth($list, $n, $value) {
  $result: ();
  @for $i from 1 through list.length($list) {
    @if $n == $i {
      $result: list.append($result, $value, list.separator($list));
    }

    $result: list.append($result, list.nth($list, $i), list.separator($list));
  }
  @return $result;
}
https://github.com/angular-package/sass/blob/main/list/_list.insert-nth.function.scss

Parameters

$list

The list to insert $value at index $n.

$n

The index $n under which $value is inserted.

$value

The value to insert at the $n index.

Return

The return value is the list with the inserted $value at the $n index.

Examples

Last updated

Was this helpful?