Can I insert multiple values in a table using table.insert?

The title says it all. So, is there a way/function available to do this?

2 Likes

No, but you can wrap it to add this function.

local function insert(tbl, ...)
    for _, value in ipairs({ ... }) do
        table.insert(tbl, value)
    end
end
9 Likes

I know that but it’d be better if I was able to insert multiple values through table.insert().

You can’t, sadly, so that is why I made that wrapper function.

2 Likes

Will this work? I think it’ll add table as whole.

table.insert(tbl,{1,2,3})
1 Like

It will add the entire table, not just its elements.

local tbl = { }
table.insert(tbl, { "a" })
print(typeof(tbl[1])) --> "table"
4 Likes