Type Function Library table.* Return value Array Revision 2017.3060 Keywords table, array See also table.concat()
Returns a shallow copy of array, i.e. the portion of the array (table) with integer keys. A variable number of additional arrays can be passed in as optional arguments. If an array has a hole (a nil
entry), copying in a given source array stops at the last consecutive item prior to the hole.
In Lua, the function table.concat()
is equivalent to JavaScript's array.join()
. Hence, the following function is called copy()
.
table.copy( t ) table.copy( t, ... )
local t1 = {1,3,5,7,9} local t2 = {2,4,6,333} t2[6] = 555 -- create hole local t3 = {11,13,17,19} local c = table.copy( t1, t2, t3 ) -- output: 1, 3, 5, 7, 9, 2, 4, 6, 333, 11, 13, 17, 19 print( table.concat( c, ", " ) )