const array1 = [
{
id: "40",
alias: "Number",
name: "Number",
},
{
id: "41",
alias: "Salary",
name: "Salary",
},
];
const array2 = [
{
id: "Sum__Salary__U3VtKFVTJTIwRW1wbG95ZWUuU2FsYXJ5KQ__",
name: "Salary",
},
{ id: "40", name: "Number" },
];
I am looking to update the 'Salary' identifier in array2 to be "41" instead of "Sum__Salary__U3VtKFVTJTIwRW1wbG95ZWUuU2FsYXJ5KQ__"
This is the code snippet I've attempted:
const result = array1
.filter((array1Value) =>
[...array2].find(
(array2Value) => array2Value.name === array1Value.alias
)
)
.map((column) => ({
id: column.id,
name: column.name,
}));
console.log("result: ", result);
The above code works well, but it creates a new set of arrays using map. Is there a more efficient way to replace the values directly without creating a new array set? Open to suggestions for a better approach.