Operation of two arrays

arr1 = [
{active:true, id:1,name: "Business Type"},
{active:true, id:2,name: "report Type"},
{active:true, id:3,name: "Asset Type"},
]

arr2 = [
{active:false, id:1,name: "business type"},
{active:false, id:2,name: "report type"},
{active:false, id:3,name: "asset type"},
{active:false, id:4,name: "business type"},
{active:false, id:5,name: "reimbursement type"}}
]

finally, arr2 = [
{active:true, id:1,name: "business type"},
{active:true, id:2,name: "report type"},
{active:true, id:3,name: "asset type"},
{active:false, id:4,name: "business type"},
{active:false, id:4, Name: "reimbursement Type"}
]
purpose is simply to change the active of arr2 that contains arr1"s thoughts to true, The active that does not contain the arr1 item will not be modified. There is no way of thinking. Several methods have been tried, but none of them are successful.

Mar.30,2021

I have no idea. I tried several methods, but none of them succeeded

Please post some of the methods you have used to let people know that you have tried

here are my thoughts

const arr1 = [
    {active:true, id:1,name: ""},
    {active:true, id:2,name: ""},
    {active:true, id:3,name: ""},
];
const arr2 = [
    {active:false, id:1,name: ""},
    {active:false, id:2,name: ""},
    {active:false, id:3,name: ""},
    {active:false, id:4,name: ""},
    {active:false, id:5,name: ""}
];
const set = new Set();
arr1.forEach(item=>set.add(item.id));
arr2.forEach(item=>{
    if(set.has(item.id)){
        item.active = true;
    }
});

console.table(arr2);

the following is the running result

clipboard.png


const arr1 = [
    {active:true, id:1,name: ""},
    {active:true, id:2,name: ""},
    {active:true, id:3,name: ""},
];
const arr2 = [
    {active:false, id:1,name: ""},
    {active:false, id:2,name: ""},
    {active:false, id:3,name: ""},
    {active:false, id:4,name: ""},
    {active:false, id:5,name: ""}
];
arr2.map(v2 => {
    const member = arr1.find(v1 => v1.id === v2.id);
    return member && member.active ? {...v2, active: member.active} : v2
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52ac8-44a0d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52ac8-44a0d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?