The js includes function is comparing items with the === operator and this doesn't work with objects.
for exmaple the following expression will return false :
{id:1} === {id:1}
To solve your problem you can use the js function some that check if one element of the array match the condition
To compare your object you can either write your logic in the some function or write another function to compare your items.
Note: In my opinion, in your case, you can only compare the identifier of the objects to check if they are included in the personNamen array
checked={personNamen.some(person => person.name === name.name)}
const personNamen = [{
name: "Foo", id: 1
}]
const name = {
name: "Foo", id: 1
}
const name2 = {
name: "Bar", id: 2
}
const compareObjects = (obj1, obj2) => {
return obj1.name === obj2.name && obj1.id === obj2.id
}
console.log(personNamen.some(person => compareObjects(person, name))) //true
console.log(personNamen.some(person => compareObjects(person, name2))) //false
Another solution would be to map the array to the value of the identifier and check if the id is included in the mapped array
Example :
const personNamen = [
{id: 1, name: "Foo"},
{id: 2, name: "Bar"},
]
const reduceArray = personNamen.map(x => x.id)
const name1 = {id:1, name: "Foo"}
const name2 = {id:3, name: "Baz"}
console.log(reduceArray.includes(name1.id)) //true
console.log(reduceArray.includes(name2.id)) //false