Thursday, March 22, 2018

Get union of 2 arrays removing intersection values (Javascript)


var array1 = ['12','1','10','19','100','test'];
var array2 = ['12','10','19','test1'];
var array3 = array1.filter(function(obj) { return array2.indexOf(obj) == -1; });
var array4 = array2.filter(function(obj) { return array1.indexOf(obj) == -1; });
gs.print('----> array1 Values----->'+  array1);
gs.print('----> array2 Values----->'+  array2);
gs.print('----> array3 Values----->'+  array3);
gs.print('----> Concat Values----->'+  array3.concat(array4));








Reference:
https://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items


1 comment:

Discovery troubleshooting | Error messages

  Discovery troubleshooting | Error messages - Support and Troubleshooting (servicenow.com) Description Learn how to resolve common Discover...