Getting a table from value, in a 2d Table

As the title says,

Let’s say I have the string “a” and I want to get table[1], how would I do that?

example = {}
example[1] = {
"a",
"b",
"c"
}
example[2] = {
"d",
"e",
"f"

I can’t just do table.find(example, “a”) right? and get example[1]. Or at least not that I’m not that aware of anything. 2D tables/arrays/vectors aren’t really covered much in guides.

You need to rephrase your question, it’s not really clear what you want.

The best way to look for the value is loop through all the values and if the value inside the main table is another table then loop through that until you find your value.

table.find will be useful for this.

example[1] = {
"a",
"b",
"c"
}
example[2] = {
"d",
"e",
"f"
}

for i, t in ipairs(example) do
    if table.find(t, "a") then
        print(i) -- example[i] is the table containing the value
    end
end

You can use this to create a function and neaten up the code a bit, but essentially you will need a foor loop and table.find.

Hope this helps :slight_smile: