Skip to content
Node: arr.findIndex(fn)github.com/sahilkhaire/gox/slice

FindIndex

Overview ​

FindIndex returns the index of the first match, or -1 (Array.findIndex).

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

Signature ​

go
func FindIndex[T any](in []T, fn func(T) bool) int

Compare: Node.js · Standard Go · gox ​

js
arr.findIndex(fn)
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.FindIndex(arr, fn)

Example ​

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

slice.FindIndex(arr, fn)

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