Files
lo/docs/data/core-nthor.md
T
2025-10-06 17:15:49 +02:00

590 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
NthOr nthor find.go#L635 core find https://go.dev/play/p/sHoh88KWt6B
core#find#nthor
core#find#nthorempty
core#find#nth
core#find#findorelse
core#find#firstor
330
func NthOr[T any, N constraints.Integer](collection []T, nth N, fallback T) T

Returns the element at index nth of collection, or the fallback if out of bounds. If nth is negative, returns the nth element from the end.

v := lo.NthOr([]int{10, 20, 30}, 10, -1)
// v == -1