I have two arrays. When I loop through the two arrays and determine that the two arrays have the same id, I change a variable in one of the arrays to true

problem description

the environmental background of the problems and what methods you have tried

I have two arrays. When I loop through the two arrays and determine that the two arrays have the same id, change a variable in one of the arrays into the true-sharp-sharp-sharp-related code
/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Mar.04,2022

arr1.forEach(item => {
  if (arr2.find(_item => item.id === _item.id)) {
    item.flag = true
  }
})

const arr1 = [
    {
        id:1,
        state:false
    },
    {
        id:2,
        state:false
    },
    {
        id:3,
        state:false
    }
];
const arr2 =  [
    {
        id:5,
        state:false
    },
    {
        id:6,
        state:false
    },
    {
        id:7,
        state:false
    },
    {
        id:1,
        state:false
    },
];

for(let i = 0 ; i < arr1.length; iPP){
    const target = arr2.find((v) => v.id === arr1[i].id);
    if (target) {
        arr1[i].state = target.state;
    }
}

arr1.map((a1) => {
    arr2.map((a2) => {
       if(a1.id === a2.id){
          a1.flag = true;//a2.flag = true
       }
    })
})
Menu