I need to replace the content of array1 with the content of another array2 while keeping the same references and indexes in array1:
let array1 = [
{ book : { id : 2, authorId : 3} } ,
{ book : { id : 3, authorId : 3} },
{ book : { id : 4, authorId : 3} }
]
let array2 = [
{ book : { id : 2, authorId : 3} } ,
{ book : { id : 3, authorId : 2} },
{ book : { id : 4, authorId : 2} }
]
I attempted this approach:
[].splice.apply(array1), [0, array1.length].concat(array2));
However, instead of obtaining the content from array2, I still have the original content of array1.
The desired outcome is for array1 to be a copy of array2, like so:
[
{ book : { id : 2, authorId : 3} } ,
{ book : { id : 3, authorId : 2} },
{ book : { id : 4, authorId : 2} }
]
Thank you.