Remove matching entries from an array
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-15-2023 10:41 PM
Hi All,
Requirement:
I have 2 arrays.
array1 = ['Software', 'Hardware', 'Service Catalog']
array2 = ['Technology', 'Governance', 'Hardware', 'HR', 'Service Desk', 'Service Catalog', 'Software']
If whatever present in array1, is matching the names in array 2, then remove those names from array 2 and give the new array.
Output should be:
array2 = ['Technology', 'Governance', 'HR', 'Service Desk']
Kindly, help with scripting.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-15-2023 10:48 PM
you can use API method ArrayUtil.diff() for your use case, see https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/c_ArrayUtilAPI#r_AU-...
Maik
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-15-2023 10:53 PM
Let's try ServiceNow ArrayUtil.
var array1 = ['Software', 'Hardware', 'Service Catalog'];
var array2 = ['Technology', 'Governance', 'Hardware', 'HR', 'Service Desk', 'Service Catalog', 'Software'];
var result = new ArrayUtil().diff(array2, array1);
gs.log(result);
Ref: ArrayUtil - Global
Cheers,
Tai Vu
