const person = {
first_name: "Sam",
last_name: "Bradley"
};
Object.values(person).includes("Bradley");
array.findIndex((obj) => obj.id === obj.id) !== -1
if (vendors.findIndex(item => item.Name == "Magenic") == -1) {
//not found item
} else {
//found item
}
// You can turn the values of an Object into an array.
// Then test that a value is present:
// This assumes, that the Object is not nested
// and the value is an exact match:
var obj = { a: 'test1', b: 'test2' };
// Note that an array can only have positive index's; so
// checking for a negative index is a super valid way for getting a
// boolean value as a result for the check.
if (Object.values(obj).indexOf('test1') > -1) {
console.log('Value exists!');
}
let hasMagenicVendor = vendors.some( vendor => vendor['Name'] === 'Magenic' )
const john = {
'name': 'John Doe',
'email': 'john.doe@example.com'
};
const jane = {
'name': 'Jane Doe',
'email': 'jane.doe@example.com'
};
const list = [john, jane];
let result = list.includes(john);
console.log(result); // true
const list = [{
'name': 'John Doe',
'email': 'john.doe@example.com'
}, {
'name': 'Jane Doe',
'email': 'jane.doe@example.com'
}];
const isEqual = (first, second) => {
return JSON.stringify(first) === JSON.stringify(second);
}
const result = list.some(e => isEqual(e, {
'name': 'John Doe',
'email': 'john.doe@example.com'
}));
console.log(result); // true