ARRAY::MERGE
1g 2023-12-16 laplante@plcb.ca GOWEB/ARRAYtitle: “ARRAY::MERGE” version: “1g” date: 2023-12-16 author: “laplante@plcb.ca”
array::merge Merges multiple arrays into the first array.
array::merge or merge(first-array[, error:variable, index:integer, array2…])
Merges multiple arrays into the first array.
By default, all provided arrays (array2...
) are appended to the end of the first array.
If index is specified, the merge occurs at that position.
If index is negative, insertion is counted from the end of the first array.
res={{
a1 := [1,2,3];
a2 := ['a','b','c'];
a3 := [true, false];
a4 := [ [5,6], [7,8] ];
a5 := [ { "x" : 100, "y" : 200 } ];
array::merge(a1,a2,a3,a4,a5); "\n";
array::merge(index:0,a1,a2,a3,a4,a5); "\n";
array::merge(index:1,a1,a2,a3,a4,a5); "\n";
array::merge(index:2,a1,a2,a3,a4,a5); "\n";
array::merge(index:3,a1,a2,a3,a4,a5); "\n";
array::merge(index:-1,a1,a2,a3,a4,a5); "\n";
array::merge(index:-2,a1,a2,a3,a4,a5); "\n";
array::merge(index:-3,a1,a2,a3,a4,a5); "\n";
}}.
Returns:
res=[1,2,3,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200}]
["a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},1,2,3]
[1,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},2,3]
[1,2,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},3]
[1,2,3,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200}]
[1,2,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},3]
[1,"a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},2,3]
["a","b","c",true,false,[5,6],[7,8],{"x":100,"y":200},1,2,3]
.
laplante@plcb.ca