DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Cover image for Array clone JavaScript
syedsimanta03
syedsimanta03

Posted on

Array clone JavaScript

Array clone JavaScript 

// `arr` is an array
const clone = arr => arr.slice(0);

// Or
const clone = arr => [...arr];

// Or
const clone = arr => Array.from(arr);

// Or
const clone = arr => arr.map(x => x);

// Or
const clone = arr => JSON.parse(JSON.stringify(arr));

// Or
const clone = arr => arr.concat([]);
Enter fullscreen mode Exit fullscreen mode

javascripts #JavascriptLibraries #javascript30 #javascripting #javascript30 #javascriptbasics #javascriptdeveloper #javascriptiskillingmysoul #javascriptdevelopers #javascriptlover

freelance #freelancer #freelancelife #freelancerlife

Top comments (1)

Collapse
 
probros profile image
PRO-BROS

Awesome explanation. Definitely helps me in improving my knowledge of JavaScript and its libraries. It will also helps me in improving my Site.

Classic DEV Post ๐Ÿ‘‡

Visualizing Promises and Async/Await ๐Ÿคฏ

async await