The includes()
method compares objects by reference and not by value. In your case the three objects have three different references although they have the same properties and the same values in them.
const bill = { name: 'Bill', age: 11 }
const arr = [bill, { name: 'Jane', age: 18 }]
arr.includes(bill) // true (same reference)
arr.includes({ name: 'Bill', age: 11 }) // false (different reference)
If you want to find objects by value, you can use the find()
method and pass a filter function which checks if each property of the object matches your criteria.
const arr = [{name:"Bill", age:11}, {name:"Jane", age:18}]
const exists = Boolean(arr.find(x => x.name === 'Bill' && x.age === 11))
// or even simpler using the `some()` method
const exists = arr.some(x => x.name === 'Bill' && x.age === 11)