How to store multiple arrays in a parent array?

Sathwik1
Tera Expert

I'm having two arrays 

 

array 1 = [ a, b,c]

array 2 = [x,y,z]

Now I need to store all these two array's in some place and if I call a[0] then I need to get output as a,b,c and if I print a[1] then I need output as x,y,z

 

can some one please help me how to satisfy this requirement?

7 REPLIES 7

Soumil
Tera Contributor

You can save the length of both the arrays

then start pushing the array elements in a single array

Where ever you require the array you can run a loop and from 0 to length of first array or length of first array till end for second array and create the array again

KrishnaMohan
Giga Sage

Hi @Sathwik1 

 

array1 = [ 'a','b','c']
array2 = ['x','y','z']
array  = [array1,array2];
array[0]; //output is ['a','b','c']
array[1]; //output is ['x','y','z']

Hi, 

Thanks for sharing the code, but after pushing array1 and array2.. I'm passing mail through to email script through event.. in email script.. array[0] is not working..can you please help me what I did the mistake?

 

var ar1 = [1,2,3,4]
var ar2 = [5,6,7,8]

 

var ar1 = [1,2,3,4]
var ar2 = [5,6,7,8]
var array = [];
array = [ar1, ar2]
gs.eventQueue('sathwik', current, array, null)

 

In email script, i have written like below

var t = event.parm1.toString();
template.print(t[0]);
template.print(t[1]);

 

in notification I am getting output as " 1,  that's it.. what is wrong ?

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

PFA

 

var array1 = ['a','b','c'];
var array2 = ['x','y','z'];

var array=[];
array.push(array1);
array.push(array2);
gs.info(array)
gs.info(array[0])
gs.info(array[1])

 

SaurabhGupta_1-1672677556767.png

 

 


Thanks and Regards,

Saurabh Gupta