diff two arrays 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"]function arraysAreIdentical(arr1, arr2){
if (arr1.length !== arr2.length) return false;
for (var i = 0, len = arr1.length; i < len; i++){
if (arr1[i] !== arr2[i]){
return false;
}
}
return true;
}
Also in JavaScript:
- ERROR in ./src/app/pages/auth/auth.module.ngfactory.js Module not found: Error: Can't resolve '@angular/material/core/index'
- how to get the value of radio button in jquery
- js remove the last character of a string
- javascript send post data with ajax
- react after deployment givin nginx 404
- get length of array
- jquery onload event
- jquery select input value empty and hasclass
- index and id together angularjs
- facebook integration in node.js
- scoll a div to bottom in angular
- cortar elemento y pegar en otro lugar jquery
- what is node.js
- create array javascript fill
- generate random whole numbers within a range
- JSX not allowed in files with extension '.js'
- node js return json
- basketball socket io
- javascript add div to body with class
- convert timestamp to date js
- how to eat beans in javascirpt
- cordova delete cache
- js copy array into another
- how to disable menu bar in browser using javascript