Is there a simpler way than looping through the table and counting the keys? I know #Table only returns the contiguous arrayed portion of the table.
How do you Get the length of a mixed/vectored table?
Posted by WillFa on Wed 20 Aug 2008 09:46 PM — 4 posts, 11,382 views.
No, if you mix integer and string keys, there is no way to get the length other than by counting. (Actually, there are some gotchas even if you use only integers, depending on whether or not you have holes and how big they are.)
Yup. I know about the gotchas.
I mainly wanted to know because I was looking for a way to see if the table's empty.
"if next(Table) then ..." solves that problem.
I mainly wanted to know because I was looking for a way to see if the table's empty.
"if next(Table) then ..." solves that problem.
Ah -- yes :) That's what the Lua people have always said: usually when people want the length, what they really want is to check if the length is zero...