if don’t know if this is most effective, but perhaps the shortest
A = [1, 2, 3, 4];
B = [1, 3, 4, 7];
diff = A.filter(function(x) { return B.indexOf(x) < 0 })
console.log(diff);
Updated to ES6:
A = [1, 2, 3, 4];
B = [1, 3, 4, 7];
diff = A.filter(x => !B.includes(x) );
console.log(diff);
More Related Contents:
- Difference and intersection of two arrays containing objects
- Filter JSON by key value with JavaScript
- Accesing 2d arrays from Javascript [closed]
- How to remove all duplicates from an array of objects?
- Determine whether an array contains a value [duplicate]
- Javascript call() & apply() vs bind()?
- Best way to find if an item is in a JavaScript array? [duplicate]
- How to convert an Object {} to an Array [] of key-value pairs in JavaScript
- What is “undefined x 1” in JavaScript?
- Why is array.push sometimes faster than array[n] = value?
- How to sort array inside collection record in MongoDB?
- Find and remove objects in an array based on a key value in JavaScript
- JavaScript – populate drop down list with array
- Explanation of [].slice.call in javascript?
- Sum of array object property values in new array of objects in Javascript [duplicate]
- What is the performance of Objects/Arrays in JavaScript? (specifically for Google V8)
- How to filter an array in javascript?
- Create an empty object in JavaScript with {} or new Object()?
- Compare 2 arrays which returns difference
- Getting a list of associative array keys
- How much faster are arrays than accessing Google Sheets cells within Google Scripts?
- Javascript remove all occurrence of duplicate element, leaving the only one that is unique
- JavaScript: Remove duplicates of objects sharing same property value
- Sieve of Eratosthenes algorithm in JavaScript running endless for large number
- What is the difference between a shallow copy and a deep copy with JavaScript arrays? [duplicate]
- JavaScript filter array by data from another
- javascript – match string against the array of regular expressions
- How to find the coordinate that is closest to the point of origin?
- Can a JavaScript variable be used in plain HTML?
- javascript – Convert array to string while preserving brackets