Thats because you're not doing .name
when checking .indexOf
var object1 = {
name: 'one',
psno: '34'
};
var object2 = {
name: 'two',
psno: '34'
};
var object3 = {
name: 'three',
psno: '345'
};
var arr1 = [object1, object2, object3];
var arr2 = [object1, object2];
// solution
var names = arr1.map(function(obj) {
return obj.name;
});
var isSuperset = arr2.every(function(val) {
//Ive changed this line!
return names.indexOf(val.name) >= 0;
});
alert(isSuperset);
JS Fiddle here:
https://jsfiddle.net/waqmafsa/