Standard library / slices
slices.Index()
Returns the first index of an equal element or -1 if absent. Expected stdout: '0 -1\n'.
Formal Syntax & Structure
go syntaxgo
func Index[S ~[]E, E comparable](s S, v E) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
| v | E | Element value or variadic values for this operation. |
Return Value
int
Returns the first index of an equal element or -1 if absent.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.Index([]int{4, 8, 4}, 4), slices.Index([]int{4, 8}, 9))}