- 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-21-2022 03:19 AM
Thanks
It helped.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2022 04:12 AM
Hi Ujjwal,
First thing to note is following lines are invalid JavaScript syntax.
var arrayA = { "a","b","c"};
var arrayB ={"c","d","e"};
Arrays in JavaScript is surrounded by square brackets "[]" and not bracket "{}". So it should be as follows.
var arrayA = [ "a","b","c"];
var arrayB =["c","d","e"];

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2022 04:17 AM
So the code will be like following.
var arrayA =[ "a","b","c"];
var arrayB =["c","d","e"];
var arrayUtil = new ArrayUtil();
var diff = arrayUtil.diff(arrayA, arrayB);
gs.print(diff);
Result:
*** Script: a,b