Codectionary / Developer documentation / Luau

Luau sequence searches

table.find returns the first index whose value equals the target or nil when absent. It searches a contiguous sequence and stops at the first nil; it does not search dictionary values.

Syntax

local index = table.find(items, value, startIndex)

Examples

Luau sequence searches

Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.

local names = {"Ada", "Lin", "Ada"}
print(table.find(names, "Ada"))
print(table.find(names, "Ada", 2))
print(table.find(names, "Bo") == nil)
  1. Output: 1, 3, true. An optional start index allows searching beyond the first occurrence.

Best practices

  • Check for nil before removal or indexing. For repeated membership checks over large data, consider a dictionary set.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading