add two arrays
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2024 10:12 PM
Hello developers, i need help in How to add two arrays to a third array in script include, Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2024 10:20 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2024 10:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2024 11:10 PM
Hello @servicenow14710 ,
var arr1 = [1, 2, [3, 4]];
var arr2 = [[5, 6], 7, 8];
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