- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 08:16 AM
Hello Team,
I am trying to remove a fixed number of groups stored in a property from a variable containing all the groups but I am not able to do it. Below is a similar code snippet where from the variable 'allgroups', I want to remove groups the groups stored in 'exgroups'. The 'gs.print' api is showing all the groups. Can someone tell me what am I doing wrong?
Code:
var allgroups = [];
allgroups = '44497c651b454110270a87b1f54bcbf5,e60cc5d9872989d4602d33b40cbb35ba,c556ead61bf45514443387fee54bcbae,c819871087dfb110e3bf98ebbbbb35af,c8262ed61bf45514443387fee54bcbf9';
var exgroups = [];
exgroups = '44497c651b454110270a87b1f54bcbf5,c556ead61bf45514443387fee54bcbae,c8262ed61bf45514443387fee54bcbf9';
for (var i = allgroups.length - 1; i >= 0; i--) {
for (var j = 0; j < exgroups.length; j++) {
if (allgroups[i] === exgroups[j]) {
allgroups.splice(i, 1);
}
}
}
gs.print(allgroups);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 08:39 AM
Hi @anirban300 ,
Please use below code -
var array1 = ['Software', 'Hardware', 'Service Catalog'];
var array2 = ['Technology', 'Governance', 'Hardware', 'HR', 'Service Desk', 'Service Catalog', 'Software'];
var newArray2 = [];
for (var i = 0; i < array2.length; i++) {
var element = array2[i];
if (array1.indexOf(element) === -1) {
newArray2.push(element);
}
}
array2 = newArray2;
gs.info(array2);
Or
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 08:39 AM
Hi @anirban300 ,
Please use below code -
var array1 = ['Software', 'Hardware', 'Service Catalog'];
var array2 = ['Technology', 'Governance', 'Hardware', 'HR', 'Service Desk', 'Service Catalog', 'Software'];
var newArray2 = [];
for (var i = 0; i < array2.length; i++) {
var element = array2[i];
if (array1.indexOf(element) === -1) {
newArray2.push(element);
}
}
array2 = newArray2;
gs.info(array2);
Or