- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 03:32 AM
hi all,
We have two array
var arrayA = { "a","b","c"};
var arrayB ={"c","d","e"};
we need to items, which is available in arrayA but not available arrayB. Expected o/p is :"a","b";
please suggest for approach.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 03:41 AM
Try something as below.
var arrayUtil = new ArrayUtil();
var a1 = new Array("a", "b", "c");
var a2 = new Array("c", "d", "e");
gs.print(arrayUtil.diff(a1, a2)); //will print a,b
gs.print(arrayUtil.diff(a2, a1));//will print b,c
Refer link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 03:41 AM
Try something as below.
var arrayUtil = new ArrayUtil();
var a1 = new Array("a", "b", "c");
var a2 = new Array("c", "d", "e");
gs.print(arrayUtil.diff(a1, a2)); //will print a,b
gs.print(arrayUtil.diff(a2, a1));//will print b,c
Refer link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 03:42 AM
Last line had a typo it will print d,e instead of b,c
gs.print(arrayUtil.diff(a2, a1));//will print d,e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2022 03:21 AM
Thanks Jaspal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 03:41 AM
Hi,
You can use the 'ArrayUtil' Script include function which is available OOB. Please see the use case below,
var a = [1,2,3,4];
var b = [2,3];
var c = new ArrayUtil().diff(a,b);
gs.info(c); // This will print > 1,4