How to check which table has the highest amount of indexes?

So I have a couple of tables:

Table1 = {...SomeIndexes...}
Table2 = {...SomeIndexes...}
Table3 = {...SomeIndexes...}
Table4 = {...SomeIndexes...}

How would I check which one has the highest amount of indexes and be able to make the code act upon this information? I mean not just print #indexes of all tables and then see by myself which one has the highest amount of indexes, but make the code understand that by itself and already give me an answer.

2 Likes
local Table1 = {...SomeIndexes...}
local Table2 = {...SomeIndexes...}
local Table3 = {...SomeIndexes...}
local Table4 = {...SomeIndexes...}
local Tables = {Table1,Table2,Table3,Table4}

table.sort(Tables, function(a,b)
      return #a>#b
end)

print("Biggest Table: "..Tables[1])
2 Likes

This code just prints the contents of Table1 and it doesn’t have the most amount of indexes.

Did you edit the indexs inside of the script?

local Table1 = {1,3,5,7}
local Table2 = {1}
local Table3 = {3.4,5}
local Table4 = {1,2,3}
local Tables = {Table1,Table2,Table3,Table4}

table.sort(Tables, function(a,b)
      return #a>#b
end)

print("Biggest Table: "..#Tables[1])
1 Like

This seems to work now, do you also know how would you get this table’s name? Right now we get only the amount of indexes. So for example if Table3 would have the most indexes how would we also retireve its name besides the amount of indexes?

I believe there is no way of calling a tables name. You could try to add the name into the table itself and then call it.

Could you mark my script as the solution? Thanks :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.