Find Value in Table/Array?

I’m wondering if there’s an easier way to see if a specific value exists within a table/array. Right now, I usually just write my own search function to see if a value exists or not, but I feel like there must be an easier way.

Python has this capability with:

l = ['example']
print('example' in l)

Which would output as True.
Is there something similar in Roblox Lua?

Thanks

2 Likes

Roblox has added table.find(t, v) which returns the index of v in t, otherwise nil if v is not in t. So you should get similar results by doing:

t = { "example" }
print(table.find(t, "example") ~= nil)

Will write true to the console.

12 Likes

Thank you, I must’ve missed that in the API reference. My bad