I am looking for an efficient way to remove all elements from a javascript array if they are present in another array.
// If I have this array: var myArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; // and this one: var toRemove = ['b', 'c', 'g'];
I want to work with myArray to leave it in this state: ['a', 'd', 'e', 'f']
With jQuery, I use grep() and inArray() , which works well:
myArray = $.grep(myArray, function(value) { return $.inArray(value, toRemove) < 0; });
Is there a pure javascript way to do this without looping and splicing?
javascript jquery arrays
Tap Nov 13 '13 at 15:13 2013-11-13 15:13
source share