Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Identifying whether a value exists inside a table without using for loop?

My question is quite simple, I was wondering if there is a more efficient way in terms of performance to find whether a value exists inside a specified table without iterating through several keys. With my current knowledge, I would have to do something like this:

local function FindTableValue(Table, Value)
	for _,v in pairs(Table) do
		if v == Value then return true end
	end
end

This is generally ok to use in many cases, but when tables start having 50+ values and I am running the finding function every frame, things can get quite slow performance wise. If this question has already been asked, I apologize as I was not able to find something similar here on the website.

1 answer

✓ Accepted answer

As far as i know thats is the quickest way ive done some research and this is what i found

Tables

2 comments

0

The research was quite interesting, not 100% what I was looking for but good enough. Thanks.

0

Of course Glad i can help in any way possible...that upvote button looks kind of juicy dont you think?

This discussion is preserved as it was. New answers, comments, and votes are closed.