array differenc javascript
let difference = arr1.filter(x => !arr2.includes(x));
function diffArray(arr1, arr2) {
return arr1
.concat(arr2)
.filter(item => !arr1.includes(item) || !arr2.includes(item));
}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 array sum
- .env not working on react
- currying vs closure javascript
- js yesterday date
- document queryselectorall and map javacript
- Javascript check if undefined
- random number generator js
- link stylesheet in javascript
- Enclose in Brackets
- react prevstate
- Firebase: Firebase App named '[DEFAULT]' already exists
- javascript append to paragraph
- javascript loop over classlist
- jest mock mockname
- js unwrap element
- react how to create range
- node.js
- How can I get or extract some string part from url jquery
- jspdf Cannot create property 'callback' on number '15'
- js code
- javascript remove first space in string
- open modal window at present cursor position javascript
- js console log input value
- javascript check if is object