# list.insert-nth()

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

{% code lineNumbers="true" %}

```scss
// 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;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/list/_list.insert-nth.function.scss>" %}

### Parameters

#### **`$list`**&#x20;

The list to insert [`$value`](#usdvalue) at index [`$n`](#usdn).

#### `$n`

The index [`$n`](#usdn) under which [`$value`](#usdvalue) is inserted.

#### `$value`

The value to insert at the [`$n`](#usdn) index.

### Return

The return value is the list with the inserted [`$value`](#usdvalue) at the [`$n`](#usdn) index.

## Examples

```scss
// Use.
@use 'angular-package/sass/list';

// Examples.
@debug list.insert-nth(('a', 'b', 'd', 'e', 'f', 'g'), 3 , 'c'); // "a", "b", "c", "d", "e", "f", "g"
@debug list.insert-nth('a' 'b' 'd' 'e' 'f' 'g', 3, 'c'); // "a" "b" "c" "d" "e" "f" "g"
@debug list.insert-nth(('a' 1) ('b' 2) ('d' 4) ('e' 5) ('f' 6) ('g' 7), 3, ('c' 3)); // ("a" 1) ("b" 2) ("c" 3) ("d" 4) ("e" 5) ("f" 6) ("g" 7)

```
