Skip to content
Node: arr.includes(x)github.com/sahilkhaire/gox/slice

Contains

Overview

Contains reports whether v is in the slice (Array.includes).

If you are coming from Node.js, the closest pattern is arr.includes(x).

Signature

go
func Contains[T comparable](in []T, v T) bool

Compare: Node.js · Standard Go · gox

js
arr.includes(x)
go
// Manual loop or Go 1.21+ slices package
for _, v := range items {
    // transform or filter v
}
go
import "github.com/sahilkhaire/gox/slice"

slice.Contains(arr, x)

Example

go
import "github.com/sahilkhaire/gox/slice"

slice.Contains(arr, x)

Tips

Chain Filter, Map, and Reduce for lodash-style pipelines. Results are new slices — inputs are never mutated.

Standard library alternative

Use a for loop or Go 1.21+ slices package helpers from the standard library.

Back to slice package overview

MIT Licensed · Built for Node.js developers moving to Go