After creating a constructor function to generate an object, I set up an array named arr1
with initial values.
Next, I use the map function on arr1
to create a new array called arr2
.
However, I noticed that the original arr1
was altered. Could this be due to the asynchronous nature of callbacks during array initialization and event loops?
On a related note, I was inspired by my previous exploration of canvas in this post when working on this code.
function point(x,y){
return {x,y}
}
arr1 = [point(1,2), point(3,4)];
console.log(arr1, "arr1");
arr2 = arr1.map(b=>{
b.x = b.x+2;
b.y = b.y+2;
return b;
})
console.log(arr1, "arr1");
console.log(arr2, "arr2");