how can I fuse two array into one to be like:
local array1 = {2272, 2271, 2270, 2269}
local array2 = {2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
local fusedArray = {2272, 2271, 2270, 2269, 2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
or
local array1 = {2292, 2291, 2290, 2289}
local array2 = {2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
local fusedArray = {2292, 2291, 2290, 2289, 2267, 2266, 2268, 2265, 2264, 2263, 2262, 2261}
The standard library can help with this:
local function concatArray(a, b)
local result = {table.unpack(a)}
table.move(b, 1, #b, #result + 1, result)
return result
end
See table.move and table.unpack in the docs.
You'll have to iterate both tables (using ipairs or pairs function) and insert elements into a third table. If you can modify one of them, then only iterate the other table and insert its elements into the first one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With