.create()
Published Oct 6, 2023
Contribute to Docs
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
Contribute to Docs
- 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.
Learn Luau on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Lua
Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.Beginner Friendly4 hours