Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add Values to an Array?

Asked by 8 years ago

Let's say I have an Array {"Hi", "Bye", "Welcome"} and I want to add an "Potato" on the [4] how can I do that? Thanks!

1 answer

Log in to vote
1
Answered by 8 years ago

Using table.insert.

Pretty easy actually;

local aa={'a',1}

table.insert(aa,3,'b') --1st argument is the table, 2nd one is the position, 3rd is the value(string, bool, int).

--To make it so it's at the last position.
table.insert(aa,#aa+1,'last')

EDIT* Made a mistake, 2nd argument is the position, the 3rd is the value.

0
If i want it to be added at the end, I use #aa + 1? Dolphinous 36 — 8y
1
Made a mistake. Fixed it though. SimplyRekt 413 — 8y
Ad

Answer this question