A shallow copy of an array is a new array that contains references to the same elements as the original array. Creating shallow copies of arrays is a common operation, especially when you want to manipulate an array without modifying the original.

There are several methods for creating shallow copies of arrays, and we’ll explore some of the most common ones: concat()slice(), and the spread operator.

Let’s start with the concat() method. This method creates a new array by merging two or more arrays. When used with a single array, it effectively creates a shallow copy. Here’s an example

let originalArray = [1, 2, 3];
let copyArray = [].concat(originalArray);
 
console.log(copyArray); // [1, 2, 3]
console.log(copyArray === originalArray); // false

In this example, we are using the concat() method to concatenate an empty array to the originalArray. This will create a new array that is a shallow copy of originalArray.

The copyArray contains the same elements as originalArray, but it is a different array object, which is why the strict equality check (===) returns false.