I want to simply exclude some array elements from another array and get the result using js and jQuery. I find my self doing a double .each() loop…
var exclude = new Array();
exclude = [1,2,3,4];
var original = new Array();
original = [0,1,2,3,4,5,6,7,8];
var finalarray = excludearrayfunction(original, exclude); // [0,5,6,7,8]
jQuery
.not()methodYou can use the jQuery
.notmethod to exclude items from a collection like so:This will return us a jQuery object, to select the result as an array we can simply do:
jsFiddle demo
Complete