let array = [
{ id: 1, name: "One" },
{ id: 2, name: "Two" },
{ id: 3, name: "Three" },
];
I have this array, I want to copy it to another array after changing one element, but my code does not work out.
array_copy = array.map((element) => {
if (element.id === 2) {
element.name = "name changed";
}
});
console.log(array_copy);
I am getting this output--
(3) [undefined, undefined, undefined]
I am new to js and self learning it, can u pls help me understand this?
Here is the link of the question Copy javaScript array by changing one element
--I tried to answer . What is wrong with my logic/approach?