Skip to main content

find-nth ()

Returns the index of the first item from a list that satisfies the test implemented by the specified function; otherwise, 0 is returned, indicating no item satisfies the test.

Parameters

$list
The list from which items will be tested.
Type
List
$predicate
The function that tests each item for a condition. The first parameter is the current item being processed in the list. The second parameter is the index of the current item being processed in the list. The third parameter is the list being processed. The returned value will be compared for truthiness.
Type
Function
$args
Additional parameters which are provided to predicate function.
Type
ArgList
Default
()

Return Value

Number
The index of the first item in the list that passes the test provided by the predicate function; otherwise, 0.

Example

@use 'sass:meta';
@use '@sass-fairy/list';

@function _greater-than-fifty($item, $void...) {
@return $item > 50;
}

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

@debug list.find-nth($list, meta.get-function('_greater-than-fifty'));
// 3