how to check if an object is in a lsit javascript code example

Example 1: javascript check if is object

obj = {
	"data": 123
}
arr = [
	"data", 
	123
]

function obj_or_arr(val) {
	if (typeof val === "object") { // return if is not array or object
		try {
			for(x of val)  // is no errors happens here is an array
				break;
			return "array";
		} catch {
			return "object"; // if there was an error is an object
		}
	} else return false; 
}

console.log(obj_or_arr(obj)) // object
console.log(obj_or_arr(arr)) // array
console.log(obj_or_arr(123)) // false
console.log(obj_or_arr("hello world")) // false
console.log(obj_or_arr(true)) // false
console.log(obj_or_arr(false)) // false

Example 2: check object in array javascript

var obj = {a: 5};
var array = [obj, "string", 5]; // Must be same object
array.indexOf(obj) !== -1 // True

Example 3: 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]
    })        
  }