I have 2 arrays this
let array1 = [
{
designation: "SSE",
emailId: "abc@gmail.com",
employeeId: 1997,
firstName: "user2",
},
{
designation: "DEVELOPER",
emailId: "ab@gmail.com",
employeeId: 19,
firstName: "user1",
},
{
designation: "DEVELOPER",
emailId: "ab@gmail.com",
employeeId: 191,
firstName: "user1",
},
];
let array2 = [
{
designation: "SSE",
emailId: "abc@gmail.com",
employeeId: 199,
firstName: "user2",
},
{
designation: "DEVELOPER",
emailId: "ab@gmail.com",
employeeId: 19,
firstName: "user1",
},
{
designation: "DEVELOPER",
emailId: "ab@gmail.com",
employeeId: 191,
firstName: "user1",
},
{
designation: "TESTER",
emailId: "ab@gmail.com",
employeeId: 1221,
firstName: "user1",
},
];
See, I have some common records in both arrays and one is missing in array2. I want to merge them into one if employeeId doesn't match. Like this.
let array3 = [
{employeeId: 1997, isActive: false},
{employeeId: 199, isActive: true},
{employeeId: 19, isActive: true},
{employeeId: 191, isActive: true},
{employeeId: 1221, isActive: false}
]
array3[3].isActive is false because it doesn't match in both arrays.