array includes object js code example
Example 1: find in array of objects javascript
let arr = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
let obj = arr.find(o => o.name === 'string 1');
console.log(obj);
Example 2: js does object contain value
var obj = { a: 'test1', b: 'test2' };
if (Object.values(obj).indexOf('test1') > -1) {
console.log('Value exists!');
}
Example 3: angular list contains property
vendors.filter(function(vendor){ return vendor.Name === "Magenic" })
Example 4: javascript array contains object
if (array.index(object) !== -1) {
console.log(`my object is in my array`)
}
if(array.includes(oject)) {
console.log(`my object is in my array`)
}