Hello everyone,
How to check if the table is empty?
Thanks!
Hello everyone,
How to check if the table is empty?
Thanks!
If you know it is an array then the length of the table will be zero.
if (#Array == 0) then
print("Array is empty")
end
If it is a dictionary you have to count the number of indices, or check if pairs
’s iterator function returns anything.
local Dictionary = {}
--// EDIT: changed pairs(t)(t) to next(t) since pairs(t) basically just returns next...
if (next(Dictionary) == nil) then
print("Dictionary is empty")
end
I wanna do a follow up on this if you can dm me:
ive got some code here:
it says this, and I’ve tried everything to try and detect if the table is empty, but it returns this no matter what. i know the table is empty but it throws an error if it is when I’m trying to address it and whatever I do before it to try and tell if it is it throws this error still
That means the table you’re trying to access is nil.
You should probably try something like this:
local table = {}
if table then
if #table == 0 then
print("table is empty")
end
else
warn("table is nil")
end
the table isnt nil because i printed it and its Table = {}, this isn’t a nil value this is an empty table.
isnt table a reserved word? im a bit confused
Replace table
with your list.