Skip to main content

insert-nth ()

Returns a list with the specified value inserted into the list at a given index.

Parameters

$list
The list to which the value is to be inserted.
Type
List
$index
The index at which the value is to be inserted. A negative index can be used, indicating an offset from the end of the list.
Type
Number
$value
The value which is to be inserted.
Type
*
$separator
The type of separator to be used by the copied list.
Type
space | comma | slash | auto
Default
auto

Return Value

List
A list with the given value inserted at the given index.

Example

@use '@sass-fairy/list';

$list: 'ant', 'bison', 'camel', 'bison', 'duck', 'elephant';

@debug list.insert-nth($list, 2, 'deer');
// 'ant', 'deer', 'bison', 'camel', 'bison', 'duck', 'elephant'