Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

Tables

0
The research was quite interesting, not 100% what I was looking for but good enough. Thanks. TheLlamaAlpaca 29 — 5y
0
Of course Glad i can help in any way possible...that upvote button looks kind of juicy dont you think? The_Pr0fessor 595 — 5y
Ad

Answer this question