Is there an efficient way to check through the Descendants of a Table?

I think we all know how to use tables:

Table = {} -- table
Table.First = 1 -- new index
Table["Second"] = {} -- alternative version

table.insert(Table, Item) -- adds Item
table.remove(Table, Item) -- removes item

But its not really what im asking, I’m more asking the question of checking the Descendants of a Table, We can use a for loop to iterate through the Children, but not what’s in the children. The Descendants.

Obviously I can have a system to iterate through the table and type check if the index value is a table, or by the usage of table.find(), but i feel like that would just cause performance issues becauase what if there is multiple?

I was wondering if it was Possible to do this while being efficient and good for Performance?

For a Better Picture:

t = { -- Table (Parent)
    t1 = { -- "Child"
        EC = {} -- "Descendant"

Its likely im overreacting here since Getting Descendants with other methods that arent tables take a bit.

If I understand correctly, you could use multiple for loops to iterate through both.

for i, v in pairs(t) do
	--// Any other code here
	for y, x in pairs(v) do
		--// Any other code here
		for w, z in pairs(x) do
			--// Any code here

Basically what I said:

But what would be a faster and less intensive way to do this?

I’m not entirely sure using table.find() a bunch is the greatest idea for performance, but it would be least intensive (writing wise); however, the multiple for loops would probably be better on performance I think.

You could just search for a table recursively

local function FindTableDescendant(Dictionary, IndexName)
   local found
   for key, val in pairs(Dictionary) do
      if typeof(val) == "table" then
         if key == IndexName then 
            found = val
            found = FindTableDescendant(val, IndexName)
   return found

P.S: i didnt test this but you get the idea

Btw You can just use type for this which appearently is slightly faster, it is not a Roblox Data Type so it would work.

However yeah, basically what ive done. It could just be me overreacting over some parts, but i was asking for a more faster way than this, if there isnt, I’ll just mark this as solution.

(My Typing sucks)

This in the worst case will go through every item in the table. With no method to skip some items knowing that the thing won’t be in there, this is the fastest you can make it.

you can probably do a repeat loop and use type()/typeof() (honestly I don’t know the difference) to check if what you got is a table and then just keep doing it until there isn’t anymore tables descending