You might think that the 3 value will have an index of 3 and the length of the table is 4 but its not
It gave me an index of 5 on value 3 and a length of 5 but wait the 3 index seems to have a value called void what is that?
Now lets make 2 undefined variables
local myTable = {
[1] = 1,
[2] = 2,
[5] = "lol"
}
now look the index of the value 3 is now 3 but wait it just gave me 3 as length of the array but its clearly 4 as you can see
anyone knows why is this happening?
It’s not a bug, but rather that the behavior of the # operator on sparse arrays is undefined and you should not rely on it. You can instead construct your tables using table.pack and read the n field to get the length instead if you really need this.