Luau .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
valueis omitted ornil, the table will be returned empty but will have preallocated space for thesizespecified. Preallocation is done on the array portion of the table, makingtable.createcounter-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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours