When dealing with sequential numbers as keys, the table is an array. Using table.insert and table.remove shifts the array to accommodate what you inserted or removed. The number 100 (not string) was at index 1, but when you inserted 500 at that position, it moved 100 to index 2. Anything dealing with arrays ignores keys that aren't sequential up from 1, which also means index 0 and negative indexes are also ignored.
The #t operation counts the array part of the table. The last part of your example makes #t == 2, since "a" is ignored.
Last edited by Kanegasi : 12-18-19 at 05:45 AM.
|