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( "tapered" )
local keys = require( "keys" )
-- util functions
local like = require( "like" )

t.ok( like( { "even", "odd", "name" }, keys{ even=2, odd=3, name="pierrot" } ) )

t.done()

See also