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 (0)