keys
function keys( tab ) --> arr
Description
Return an array table containing all the keys in the table.
Parameters
- tab
-
The table from where you want to read the keys.
Return Values
- keylist
-
An array table with the keys.
Code
--ZFUNC-keys-v1 local function keys( tab ) --> arr local arr = {} for k, v in pairs( tab ) do table.insert( arr, k ) end return arr end return keys
Examples
local t = require( "taptest" ) local keys = require( "keys" ) local like = require( "like" ) res = keys{ even=2, odd=3, name="pierrot" } t( like( res, { "even", "odd", "name" } ), true ) t()