# string.index()

The `string.index()` function returns index or list of indexes of [`$substrings`](#usdsubstrings...).

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:list';
@use 'sass:meta';
@use 'sass:string';

// The `string.index()` function.
@function index($string, $substring, $substrings...) {
  @if type-of($string) == string {
    $result: ();
    @each $substring in list.join($substring, $substrings, comma) {
      $result: list.append(
        $result,
        if(
          meta.type-of($substring) == string,
          string.index($string, $substring),
          null
        ),
        comma
      );
    }
    @if list.length($result) > 0 {
      @return if(list.length($result) == 1, list.nth($result, 1), $result);
    }
  }
  @return null;
}
```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/string/_string.index.function.scss>" %}

### Parameters

#### `$string`

The value to check whether it contains given [`$substring`](#usdsubstring) and/or [`$substrings`](#usdsubstrings...).

#### `$substring`

A substring to find in [`$string`](#usdstring).

#### `$substrings...`

The list of substrings to find in [`$string`](#usdstring).

### Return

The return value is the index or list of indexes of the given found substrings.

## Examples

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

// Examples.
// Single
@debug string.index("Helvetica Neue", "Helvetica"); // 1
@debug string.index("Helvetica Neue", "Neue"); // 11

// Multiple
@debug string.index("Helvetica Neue", "Helvetica", "Neue"); // 1, 11
@debug string.index("Helvetica Neue", "Helvetica", "Neue", "Wrong"); // 1, 11, null
@debug string.index("Helvetica Neue", "Helvetica", "Neue", "Wrong", true); // 1, 11, null, null

// Different type of the `$string`
@debug string.index(true, "Helvetica"); // null

```
