object array check values in another object array code example
Example 1: check object in array javascript
var obj = {a: 5};
var array = [obj, "string", 5]; // Must be same object
array.indexOf(obj) !== -1 // True
Example 2: react array if id is present do not add element
addPerson = (person) => {
let filteredPerson = this.state.likes.filter(like => like.name !== person.name);
this.setState({
likes: [...filteredPerson, person]
})
}