javascript check if two arrays contain same values
const a = ['Left', 'Right'];
const b = ['Right', 'Left'];
// true if a and b contain the same values
// false otherwise
const c = a.sort().join(',') === b.sort().join(',');
how to check two different length array values are equal in javascript
var a = [2, 4, 10];
var b = [1, 4];
var newArray = [];
for (var i = 0; i < a.length; i++) {
// we want to know if a[i] is found in b
var match = false; // we haven't found it yet
for (var j = 0; j < b.length; j++) {
if (a[i] == b[j]) {
// we have found a[i] in b, so we can stop searching
match = true;
break;
}
// if we never find a[i] in b, the for loop will simply end,
// and match will remain false
}
// add a[i] to newArray only if we didn't find a match.
if (!match) {
newArray.push(a[i]);
}
}