Single Operation to Concatenate 2 %DynamicArrays?
Hello,
Is there a single ObjectScript operator or method to concatenate two %DynamicArrays?
I'm looking for something that will do the following:
set arr1 = [ 1, 2, 3 ] set arr2 = [ 4, 5, 6 ] set arrcombined = arr1.%Concatenate(arr2)
or
set arrcombined arr1_arr2
With end result:
zw arrcombined arr1=[1,2,3,4,5,6] ; <DYNAMIC ARRAY>
I can iterate and %Pop over the 2nd array and %Push each popped entry to the 1st array, but I was looking for something more succinct.
Thanks in advance.
Product version: IRIS 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1.1 (Build 347U) Thu Jul 18 2024 17:35:51 EDT
Discussion (0)0
Comments
I found an answer (thanks @Pravin Barton)
Code sample to concatenate JSON arrays | InterSystems Developer Community |
USER>zw [1,2,3].addAll([4,5,6])
[1,2,3,4,5,6] ; <DYNAMIC ARRAY>
USER>w$zv
IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2024.1and, by the way, it's chainable
USER>zw [1,2,3].addAll([4,5,6]).addAll([7,8,9])
[1,2,3,4,5,6,7,8,9] ; <DYNAMIC ARRAY>Thank you Dmitry; I confirmed it works when the dynamic arrays are stored in variables:
%SYS>w $zv IRIS for Windows (x86-64) 2024.1.1 (Build 347U) Thu Jul 18 2024 17:35:51 EDT %SYS>set arr1 = [1,2,3] %SYS>set arr2 = [6,5,4] %SYS>zw arr1.addAll(arr2) [1,2,3,6,5,4] ; <DYNAMIC ARRAY> %SYS>do arr1.addAll(arr2) %SYS>zw arr1 arr1=[1,2,3,6,5,4,6,5,4] ; <DYNAMIC ARRAY>