- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:17 PM
Hi Guys,
I need you assistance.....
I have an array of names, lets call it original members ["jo", "john", "jan" ]...
I have another array of names, lets call it new members ["jo", "john", "kevin", "joe" ] ...
I have 2 variables to populate as to which names were added and removed.
Based on my list, Kevin and Joe are new members and Jan was removed. Could someone please assist as to how I can accomplish this.
Thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 02:00 PM
Its as easy as
//You just need to revers them
//This will return "jan" in an array
var removedMembers = au.diff(origMembers, newMembers);
//This will return "kevin" and "joe" in an array
var addedMembers = au.diff(newMembers, origMembers);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:22 PM - edited 09-11-2023 12:24 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:23 PM
In your instance there is a script include called ArrayUtil that has a diff method that you can use for this.
You just need to call it twice, once for orig-new and then new-orig and that will tell you what was removed and what was added.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:27 PM
HI @JLeong
Hope you are doing great.
To determine the added and removed members, you can use simple array operations. Here's a concise solution:
// Define the original and new arrays
const originalMembers = ["jo", "john", "jan"];
const newMembers = ["jo", "john", "kevin", "joe"];
// Find added members
const addedMembers = newMembers.filter(name => !originalMembers.includes(name));
// Find removed members
const removedMembers = originalMembers.filter(name => !newMembers.includes(name));
// Result
gs.info("Added members:", addedMembers);
gs.info("Removed members:", removedMembers);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:55 PM
Thank you guys! I will try them and let you know.