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) bool

Parameters & Attributes

NameTypeDescription
sSInput slice; may share its backing array.
vEElement 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))}
Go Reference