Concat N arrays in servicenow?

sonalee
Kilo Contributor

Hi Team,

Can anyone help me to concat multiple arrays ?

Array Util could help me to concat 2 arrays but I do have 4 arrays to concat.

Can I use

var arrayUtil = new ArrayUtil();

var a1 = new Array("a", "b", "c");

var a2 = new Array("c", "d", "e");

var a3 = new Array("1","2","3");

arrayUtil.concat(a1, a2,a3)) ????

Thanks,

Sonali

8 REPLIES 8

sonalee
Kilo Contributor

I wish if I would see this result.



Code Snippet :



var ids = [];


var ids2 = [];



var arrayUtil = new ArrayUtil();


ids=arrayUtil.concat(a1, a2);


ids2=arrayUtil.concat(ids, a3);



gs.log(ids2);




But I can see result as : a,b,c,c,d,e,1,2,3,1,a,b,c



Any Help ?



Thanks,


Sonali


lSurya 24
Giga Guru

Hello,



var a = [1, 2], b = ["x", "y"], c = [true, false];
var d = a.concat(b, c);
console
.log(d); // [1, 2, "x", "y", true, false];



use the above code to reflect your requirement.


Hello Sonali,



If my answer assisted you, Can you please mark my answer as correct.


DB1
Tera Contributor

Hi, 

Need help on below requirement please

I have a field and that field has values comma separated

Ex - Name = " Hi this is a , UI policy"

in this case if I mention gr.name.getDisplayValue() it displays only Hi this is a  

How to join this two comma separated and display it properly?

Thanks,

DB