TheAlmightyGuru
Newcomer
- Joined
- Aug 18, 2021
- Messages
- 2
- Reaction score
- 0
I've read that the correct way to remove an entry from a table is to simply set it to nil. However, when I try to do this, I inadvertently remove all subsequent entries as well. Here is my sample code:
I would expect the remaining output to look like this:
1 a
3 c
4 d
But, it only prints the first record:
1 a
Does anyone know what I'm doing wrong?
Code:
arr = {'a', 'b', 'c', 'd'}
for index, row in ipairs(arr) do
print(index, row)
end
arr[2] = nil -- Remove the second entry.
print("remaining:")
for index, row in ipairs(arr) do
print(index, row)
end
I would expect the remaining output to look like this:
1 a
3 c
4 d
But, it only prints the first record:
1 a
Does anyone know what I'm doing wrong?