Need help with dictionaries | How to sort indexes again after removing an index in a dictionary?

Hello Dev Forum, I was making an inventory system but when I tried to make a remove item function, I noticed that the indexes in the dictionary used in the system remained un-effected. I would like to know if there is any way to resolve this.

Examples

local Dictionary = {
   [1] = {Name = "Apple", Value = 1}
   [2] = {Name = "Orange", Value = 2}
   [3] = {Name = "Banana", Value = 4}
}

  table.remove(Dictionary,2)
  print(Dictionary)

Output:

   [1] = {Name = "Apple", Value = 1}
   [3] = {Name = "Banana", Value = 4}

I simply want the 3rd index to turn into the 2nd index.

table.remove already does this for you.

1 Like

Nevermind, I just instead used a for loop to reduce the indexes after.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.