javascript difference between two arrays
let difference = arr1.filter(x => !arr2.includes(x));
javascript difference between two arrays
let difference = arr1.filter(x => !arr2.includes(x));
diff two arrays javascript
function diffArray(arr1, arr2) {
return arr1
.concat(arr2)
.filter(item => !arr1.includes(item) || !arr2.includes(item));
}
compare two arrays and return the difference javascript
let difference = arr1
.filter(x => !arr2.includes(x))
.concat(arr2.filter(x => !arr1.includes(x)));
comparing two arrays in javascript returning differences
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"]
comparing two arrays in javascript
const arr1 = [1, 2, 3];
const arr2 = [1, 3, 3];
if (arr1.length !== arr2.length) return console.log("false");
for (let i = 0; i < arr1.length; i++) {
for (let j = 0; j < arr2.length; j++) {
if (arr1[i] === arr2[j]) {
console.log("yes match", arr1[i], arr2[j]);
continue;
}
console.log("no match", arr1[i], arr2[j]);
}
}
how to compare two arrays javascript
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us