Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

add two arrays

servicenow14710
Tera Expert

Hello developers, i need help in How to add two arrays to a third array in script include, Thanks!

3 REPLIES 3

surajchacherkar
Mega Guru

Hi @servicenow14710 ,

 

Please check the below link and you can use the concat() method to merge two arrays

 

https://www.w3schools.com/jsref/jsref_concat_array.asp

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.


Thanks

Suraj!

 

Maddysunil
Kilo Sage

@servicenow14710 

 

 

var array1 = [1, 2, 3];
        
        // Second array
        var array2 = [4, 5, 6];
        
        // Third array to store the result
        var array3 = [];
        
        // Concatenate array1 and array2 into array3
        array3 = array3.concat(array1, array2);
        
        // Logging the result
        gs.info("Concatenated Array: " + array3);

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Sanket Landge
Tera Expert

Hello @servicenow14710 ,

 

var arr1 = [12, [34]];
var arr2 = [[56], 78];
var arr3 = arr1.concat(arr2);

 

arr.concat() method is used to marge array, please mark correct and help others to find this early.

 

Thanks,

Sanket Landge