Skip to main content

index ()

Returns the first index at which a specified item can be found in a list; otherwise, 0 is returned, indicating the item is not present.

Parameters

$list
The list from which the value is to be located.
Type
List
$value
The value to locate in the list.
Type
*
$start-at
The index at which to begin the search. A negative index can be used, indicating an offset from the end of the source string.
Type
Number
Default
1

Return Value

Number
The index of the first occurrence of the value; otherwise, 0.

Example

@use '@sass-fairy/list';

$list: 32 8 65 79 34 8 13 66 18;

// 1. Get the index of `8`
@debug list.index($list, 13);
// 2

// 2. Get the index of `8` starting a specific index
@debug list.index($list, 8, -6);
// 7