Table.remove doesn't remove a specific index

local array = {"e", 274.219, false}
array[190] = "tbd"
print(array)
table.remove(array, 190)
print(array)    --- this prints the samething as above:

▼ {
[1] = “e”,
[2] = 274.219,
[3] = false,
[190] = “tbd”
}

When i try to remove any other index beside 190, it works. I’m confused.

If you use table.remove(array, 4), what do you get?

it doesn’t do anything either.

Try using table.insert() instead, see where that gets you.
I can’t exactly get on Studio to test this stuff at the moment, sorry about the inconvenience.

I believe your issue is because 190 is not an increment of the previous index and thus it does not see the array as a table, but rather as a dictionary, tables are sequential arrays, meaning the indexes increase by 1, but in this case it went from 4 to 190, you’d need to either change 190 to 4 or do array[190] = nil instead

2 Likes

This seemed to work for me.

local array = {"e", 274.219, false}
table.insert(array, 190, "tbd")
print(array)
array[190] = nil
print(array)

@aaltUser I can set the index to 190 using table.insert(), but once again, I cannot remove it
@EmbatTheHybrid Hmm, if that’s the case then it means that I can’t set an index to a number that I want ;/.

Yea setting it to nil does remove the index(kinda), but it doesn’t erase the index, which I must delete for my scenario.

You can set it to a number that you want, but in your case you cannot use things like table.insert, table.remove, and other table library functions on it as it’s not longer considered a table, you need to do it yourself such as array[190] = whatever and array[190] = nil, though for other functions you’ll need to figure out how to code yet

What do you mean by other functions?

table.concat, table.clear, table.find, if you need to use those functions for an array like yours, you need to code them yourself as well

I see. I will mark your first post as solution for now.

1 Like