Clone array in ES6 Last Updated : 14 Oct, 2025 Comments Improve Suggest changes Like Article Like Report The spread operator in ES6 is used to clone an array, whereas the slice() method in JavaScript is an older way that provides 0 as the first argument. These methods create a new, independent array and copy all the elements of oldArray to the new one i.e. both these methods do a shallow copy of the original array.Example javascript // Cloning array using spread operator- ES6 const oldArray = ["dog1", "dog2", "dog3"]; const clonedArrayES6 = [...oldArray]; // ["dog1", "dog2", "dog3"] console.log(clonedArrayES6); Output[ 'dog1', 'dog2', 'dog3' ] Syntax: // Older wayvar clonedArray = oldArray.slice(0) // ES6 way: spread operatorvar clonedArrayES6 = [...oldArray] Equality and samenessThe = operator assigns a reference to the original array instead of copying its elements.The spread operator (...) creates a new array with the same values but different references.= results in a shallow reference, meaning changes to one array affect the other.The spread operator produces a shallow copy, so the new array is independent but only one level deep.The new array from the spread operator has the same values but is not the same object as the original array.Example: This example shows the use of the above-explained approach. javascript // Equality and sameness in cloning array const oldArray = ["dog1", "dog2", "dog3"]; const clonedArrayES6 = [...oldArray]; const newArray = oldArray; // False, i.e. shallow copy console.log(clonedArrayES6 === oldArray) // True, i.e. deep copy console.log(newArray === oldArray) Outputfalse true Note: All the above examples can be tested by typing them within the script tag of HTML or directly into the browser’s console. Create Quiz Comment S Srishtibajpai Follow 0 Improve S Srishtibajpai Follow 0 Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2019 ES6 +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like