To subtract (remove) values from one comma-separated string (the "big" string) using another comma-separated string (the "small" string) in ServiceNow
var bigString = "a,b,c,d,e"; var smallString = "b,d"; // Step 1: Split both strings into arrays var bigArray = bigString.split(','); var smallArray = smallString.split(','); // Step 2: Filter the bigArray to exclude values in smallArray var resultArray = bigArray.filter(function(item) { return !smallArray.includes(item.trim()); }); // Step 3: Join the filtered array back into a comma-separated string var finalResult = resultArray.join(','); console.log(finalResult); // Output: "a,c,e"
Remove comma-separated values from two fields ServiceNow
Working Code Asked question October 14, 2024