here’s how I would implement it:
window.onload=function(){
var array1 = [1, 2, 3, 4, 5, 6]
var array2 = [3, 4, 5, 6, 7, 8]
var result = []
var resultCount=0;
for (var i1 = 0; i1 < array1.length; i1++) {
var comparedElement = array1[i1];
var isUnique = true;
for (var i2 = 0; i2 < array2.length; i2++) {
if (comparedElement == array2[i2]) {
isUnique = false;
break;
}
}
if (isUnique) {
result[resultCount]=comparedElement;resultCount++;
}
}
for (var i2 = 0; i2 < array2.length; i2++) {
var comparedElement = array2[i2];
var isUnique = true;
for (var i1 = 0; i1 < array1.length; i1++) {
if (comparedElement == array1[i1]) {
isUnique = false;
break;
}
}
if (isUnique) {
result[resultCount]=comparedElement;resultCount++;
}
}
console.log(result)
}
The code tries to find each of the elements in an array in the other array, and if it doesn’t find it, it adds it to the results array and if not, it just skips it. This might not be the most efficient way to solve this though.
3
solved How to compare two different arrays without methods? [closed]