Standard library / slices
slices.Contains()
Reports whether an equal element is present; uses ordinary == equality, not special NaN handling. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Contains[S ~[]E, E comparable](s S, v E) boolParameters & 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
bool
Reports whether an equal element is present; uses ordinary == equality, not special NaN handling.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.Contains([]int{2, 4, 6}, 4))}