Add: Difference between revisions
Jump to navigation
Jump to search
imported>Dddaaannn (add() returns the object being added.) |
imported>Felice Enellen (Fix a mistaken comment about how add() works) |
||
| Line 7: | Line 7: | ||
The <code>add()</code> function appends an element to the end of a sequence in a table. | The <code>add()</code> function appends an element to the end of a sequence in a table. | ||
This always adds the new element immediately after the current final index. It does ''not'' check for available gaps between the start and the end. | |||
The <code>add()</code> function returns the object being added. | The <code>add()</code> function returns the object being added. You can ignore this return value, or pass it back to your own caller. | ||
== Examples == | == Examples == | ||
Revision as of 16:55, 24 January 2018
add( tbl, v )
- Adds a element to the end of a sequence in a table.
- tbl
-
- The table.
- v
-
- The value to add.
The add() function appends an element to the end of a sequence in a table.
This always adds the new element immediately after the current final index. It does not check for available gaps between the start and the end.
The add() function returns the object being added. You can ignore this return value, or pass it back to your own caller.
Examples
t = {1, 3, 5}
add(t, 7) -- t = {1, 3, 5, 7}
add(t, 9) -- t = {1, 3, 5, 7, 9}