Destructuring & Spread Operator
How do you use the spread operator to create a shallow copy of an array?
To create a shallow copy of an array using the spread operator, you write `const copy = [...array];`. This syntax creates a new array and expands all elements of the original array into it. It's a concise and popular way to clone arrays in modern JavaScript. It's important to note that this creates a shallow copy, meaning that if the array contains objects or nested arrays, those will still be references to the original objects (not deep copies). A shallow copy is sufficient for arrays of primitive values (numbers, strings, booleans). The spread operator provides a clean alternative to other array copying methods like `Array.from(array)`, `array.slice()`, or `[].concat(array)`. If you need a deep copy for nested data structures, you would need to use more complex approaches like `JSON.parse(JSON.stringify(array))` (with limitations) or a dedicated deep-cloning library.