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

600 B

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

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

v := lo.NthOrEmpty([]int{10, 20, 30}, 10)
// v == 0