Quantcast WoWInterface - View Single Post - Removing a table key?
View Single Post
09-09-14, 08:01 AM   #5
A Pyroguard Emberseer
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,696
Setting the value to nil effectively removes the key from the table.

Also, ipairs halts when it hits the first nil value (and it can't read the key afaik), and it also is slower than any other option.
Use pairs, or better yet, next for your iteration needs.

local t = {
    [1] = true,
    [2] = nil,
    [3] = false

for k, v in ipairs(t) do
    print('ipairs', k, v)

-- prints [1] = true

for k, v in next, t do
    print('next', k, v)

-- prints [1] = true, [3] = false
ipairs is basically the equivalent of a for loop for associative arrays, and should only be used if necessary.

Last edited by p3lim : 09-09-14 at 08:10 AM.
  Reply With Quote