I have two sets of data called oldArray and newArray.
The goal is to update objects in oldArray with those from newArray if the makeLineName and makeProcessTypeId are the same in both arrays.
For example - In oldArray, we have TestDemo1 and Test565 under makeLineName, and these same values are also present in newArray. Therefore, I need to search for TestDemo1 and Test565 in newArray and replace the respective fields in oldArray with the matching makeLineName object from newArray.
If a matching makeLineName is not found in newArray, then the original object in oldArray will remain unchanged.
oldArray = [
{
makeLineName: "TestDemo1",
avtBCT: 80,
MaxBCT: 80
},
{
makeLineName: "Test565",
avtBCT: '',
MaxBCT: ''
},
{
makeLineName: "Luck",
avtBCT: 60,
MaxBCT: 60
}
];
const newArray = [
{
makeLineName: "TestDemo1",
avtBCT: 500,
MaxBCT: 500
},
{
makeLineName: "Test565",
avtBCT: 600,
MaxBCT: 600
}
];
Expected Output:
filteredData = [
{
makeLineName: "TestDemo1",
avtBCT: 500,
MaxBCT: 500
},
{
makeLineName: "Test565",
avtBCT: 600,
MaxBCT: 600
},
{
makeLineName: "Luck",
avtBCT: 60,
MaxBCT: 60
}
];