Jump to content

Module:table/sparseIpairs

From Wiktionary, the free dictionary

local table_num_keys_module = "Module:table/numKeys"  local function num_keys(...) num_keys = require(table_num_keys_module) return num_keys(...) end  --[==[ An iterator which works like `ipairs`, but which works for sparse arrays.]==] return function(t) local keys, i = num_keys(t), 0 return function() i = i + 1 local k = keys[i] if k ~= nil then return k, t[k] end end end