javascript difference between two arrays
let difference = arr1.filter(x => !arr2.includes(x));let difference = arr1.filter(x => !arr2.includes(x));
function arrayDiff (a1, a2) {
var a = [], diff = [];
for (var i = 0; i < a1.length; i++) {
a[a1[i]] = true;
}
for (var i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
delete a[a2[i]];
} else {
a[a2[i]] = true;
}
}
for (var k in a) {
diff.push(k);
}
return diff;
}
//usage:
console.log(arrayDiff(['red', 'white','green'], [ 'red','white', 'blue']));//["green", "blue"]
Also in JavaScript:
- js push multiple arguments
- react how to export component
- jqeury cdn
- sort javascript array
- javascript getters and setters
- tip in js
- reduce function javascript
- Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
- has class in jquery
- for each array javascript
- javascript check if objects are equal
- add edit delete from table using jquery
- cannot find module @babel/compat-data/data/corejs3-shipped-proposals
- how to update angular version
- javascript title string
- node js change text color
- format string of names
- jquery to copy two input fields into one with a space between
- mongoose bulk update
- how to make page scroll to the top jsx
- discord.js bad word filter
- javascript typeof shows object
- jquery remove css
- js object properties