var visibleObjects = [124,125];
var allObjects = [124,125,126];
function сomparison(arr1,arr2){
var idx = 0, arr3 = [];
for (var i = 0; i < arr2.length; i++){
idx = arr1.indexOf(arr2[i]);
if (idx >= 0) arr3.push(arr2[i]);
}
return arr3;
}
console.log('needremove', сomparison(allObjects,visibleObjects));
Array.prototype.diff = function(a) {
return this.filter(function(i) {return a.indexOf(i) < 0;});
};
const diffArray = (arr1, arr2) => {
const newArr = [];
for (let key of arr1) {
if (arr2.indexOf(key) === -1) {
newArr[newArr.length] = key;
}
}
for (let key of arr2) {
if (arr1.indexOf(key) === -1 && newArr.indexOf(key)) {
newArr[newArr.length] = key;
}
}
return newArr;
}