Module:Includes/doc explained

Lua equivalent to the javascript Array.prototype.includes function, except fromIndex is 1-indexed instead of zero-indexed. Determines whether an array includes a certain value and returns true or false.

Syntax

includes(array, searchElement)includes(array, searchElement, fromIndex)

array

array is the array to search. If type(array) ~= 'table' the module will return false.

value

value is the value to be tested. If value is present in the array, the module will return true. If value is missing the module will return false.

fromIndex

fromIndex is the optional 1-based index at which to start searching. If fromIndex is not present, all values in the array will be searched and the array will be treated as a table/associative array (it will be iterated over using pairs).

If fromIndex is present and an integer, the array is assumed to be a conventional array/sequence/list (indexed with consecutive integer keys starting at 1, and interated over using ipairs). Only the values whose index is fromIndex or higher will be searched.

In the following examples, #array represents the length of the integer-keyed portion of the array.

Usage

local includes = require('Module:Includes')

-- These will return trueincludes("b")includes("b", 0)includes("b", 1)includes("b", 2)includes("b", -3)includes("b", -5)includes("b")includes("b", 0)includes("b")

--these will return falseincludes("b","b") -- array is not a tableincludes -- value missingincludes("e") -- "e" is not in arrayincludes("b", 3) -- "b" is before position 3includes("b", 5) -- 5 is larger than #arrayincludes("b", -2) -- "b" is not in the last two positionsincludes("b", 0) -- key 100 is non-consecutiveincludes("b", 0) -- key "second" is not an integer