Answers for "js array includes object"

0

js array includes object

let hasMagenicVendor = vendors.some( vendor => vendor['Name'] === 'Magenic' )
Posted by: Guest on September-17-2021
3

angular list contains property

vendors.filter(function(vendor){ return vendor.Name === "Magenic" })
Posted by: Guest on March-09-2020
1

how to Check if an array contains an object in javascript

// To check if an array contains an Object

const myArrayObj = [{
    'username': 'Player 1',
    'email': '[email protected]'
}, {
    'username': 'Player 2',
    'email': '[email protected]'
}];

// Create a helper function to compear the objects
const isEqual = (first, second) => {
    return JSON.stringify(first) === JSON.stringify(second);
}

const result = myArrayObj.some(e => isEqual(e, {
    'username': 'Player 1',
    'email': '[email protected]'
}));

console.log(result); // true
Posted by: Guest on December-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language