http://jsfiddle.net/0czdrn7t/4/
I try to compare two array ,
find object(Type
= 4) in array arrayB
and if all object(Type
= 4) Privilege
not match the arrayA
value, then insert to arrayC
.
for this example the arrayA[0]
is 1 already match in arrayB
last object then I don't want it push into the result, want's wrong with my code??
var arrayA = [1];
var arrayB = [ { Type: 1,
Privilege: 0,
},
{ Type: 3,
Privilege: 0,
},
{ Type: 3,
Privilege: 1,
},
{ Type: 4,
Privilege: 1,
} ];
var arrayC = [];
var type = 4;
for (var i = 0; i < arrayA.length; i++) {
var insertValidate = true;
var issetTypeValidate = false;
for (var ii = 0; ii < arrayB.length; ii++) {
if (arrayB[ii].Type == type) {
if (arrayB[ii].Privilege != arrayA[i]) {
insertValidate = false;
// break;
}
issetTypeValidate = true;
}
}
if (issetTypeValidate == true) {
if (insertValidate == true) {
var o = {};
o.Type = type;
o.Privilege = arrayA[i];
arrayC.push(o);
}
} else {
// var o = {};
// o.Type = type;
// o.Privilege = arrayA[i];
// arrayC.push(o);
}
}
console.log(arrayC);