.create()
The .create()
function generates a new table with a specified value repeated a given number of times.
Syntax
table.create(size, value)
size
: A number representing the number of elements in the table.value
: A string representing the value each element will be.
Note: When
value
is omitted ornil
, the table will be returned empty but will have preallocated space for thesize
specified. Preallocation is done on the array portion of the table, makingtable.create
counter-productive on dictionaries.
Example
Consider the following table:
local newTable = table.create(3, "Hello")for i = 1, 3 doprint(newTable[i])end
After executing this code, it will produce the following output:
HelloHelloHello
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.