Remove object safely from display and table

I use the following code to create an object and add it to the table with unique id.

players = {} local character = display.newSprite( myImageSheet , sequenceData ) id = crypto.digest( crypto.md5, system.getTimer()  ..  math.random() ) players[id] = character

Now how to safely remove it from display and table also???

local pairs = pairs --just for speed up for k, v in pairs(players) do v:removeSelf() players[k] = nil end

I didn’t get it…

Will it remove all the items from the table? because i only want to remove one item.

If you have table based on keys (not indexes) then this will be enough

players[idToRemove]:removeSelf() players[idToRemove] = nil

Above was for whole table, this is for character with idToRemove key

– double post –

local pairs = pairs --just for speed up for k, v in pairs(players) do v:removeSelf() players[k] = nil end

I didn’t get it…

Will it remove all the items from the table? because i only want to remove one item.

If you have table based on keys (not indexes) then this will be enough

players[idToRemove]:removeSelf() players[idToRemove] = nil

Above was for whole table, this is for character with idToRemove key

– double post –