Identification if object [1] matters?

Is there a way I can determine if part of my table / array contains a value

Example

Table: object = {a, b, c, d, e}

Now I would like to know if object [1] contains a value?

especially if my table is constantly growing

is "object [1] .hasValue" does the code exist?

+3
source share
2 answers

In lua, a table that does not have a value for a key is the same as a value for which the key is zero. So you can just write

if object[1]~=nil then
 ...
end 
+5
source

you can directly check it, with the condition as shown below:

if( object[1] ) then
    print("has value");
else
    print("nil");
end
+1
source

All Articles