js includes object value code example

Example 1: js does object contain value

// 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!');
}

Example 2: angular list contains property

vendors.filter(function(vendor){ return vendor.Name === "Magenic" })

Example 3: javascript object includes

const person = {
  first_name: "Sam",
  last_name: "Bradley"
};

Object.values(person).includes("Bradley");

Example 4: check if property has value in array javascript

const magenicVendorExists =  vendors.reduce((accumulator, vendor) => (accumulator||vendor.Name === "Magenic"), false);