元素过滤

数组和集合 / 数组

local numbers = {1, 2, 3, 4, 5}

-- No filter in the library: a loop puts
-- the items that pass the test in a new array
local odd_items = {}
for _, number in ipairs(numbers) do
  if number % 2 == 1 then
    odd_items[#odd_items + 1] = number
  end
end
-- odd_items = 1, 3, 5

print("odd_items = "
      .. table.concat(odd_items, ", "))