Thursday, 15 August 2013

Subtract one Javascript Arry from another

var array1 = [1,2,3,5,7,9];
var array2 = [3,5];

var arrray1MinusArray2= $(array1).not(array2).get();

// result is arrray1MinusArray2 = [1,2,5,7,9]


var arrray2MinusArray1= $(array2).not(array1).get();

//result is arrray2MinusArray1=[]

It works with both primitive and object type. 

No comments:

Post a Comment