Module:Util/tables/len: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local clone = require("Module:Util/tables/clone")
local function len(tbl)
 
local count = 0
local function len(array)
for i in ipairs(tbl) do
-- The # operator won't work on tables loaded via mw.loadData so we have to clone them first
count = count + 1
return #clone(array)
end
return count
end
end


return len
return len

Latest revision as of 17:30, 12 May 2024

len(tbl)

Returns

  • The length of the array component of tbl. Unlike the # operator, this function works with frame.args and tables loaded via mw.loadData.

Examples

#InputOutputResult
1
len({1, 2, 3, [10] = 10})
3
2
len({ foo = "bar" })
0

local function len(tbl)
	local count = 0
	for i in ipairs(tbl) do
		count = count + 1
	end
	return count
end

return len