I was wondering recently what the best way to copy/clone an array in JavaScript is? So in this video I'm comparing 8 different copy/clone methods including 3 deep copy/clone methods and timing how long each takes to complete.
FREE Audible trial ➜ 📚 https://amzn.to/3DEW2al 📚
These results genuinely surprised me and lead me to update my SOP.
Methods compared:
[...arr]
arr.slice()
[].concat(arr)
arr.map(...)
arr.forEach(...)
JSON.parse(JSON.stringify(arr))
cloneDeep(arr)
clone(arr)
Thanks for watching, if you want to learn more about JavaScript please check out my other videos and the links below!
👇👇👇
https://www.npmjs.com/package/lodash
https://www.npmjs.com/package/clone
––––––––––––––––––––––––––––––
⏲ Timestamps:
0:00 Intro
0:08 Pre Experiment
0:30 Different Methods
1:04 Attempt 1
1:32 Attempt 2
2:15 Memory Issues
2:38 Results
3:57 Post Experiment
4:04 Outro
––––––––––––––––––––––––––––––
DISCLAIMER: Links included in this description might be affiliate links. If you purchase a product or service with the links that I provide I may receive a small commission. There is no additional charge to you! Thank you for supporting me so I can continue to provide you with free content each week!
Watch video What's the Best Way to Copy/Clone an Array in JavaScript? (comparison) online, duration hours minute second in high quality that is uploaded to the channel Apes in Capes 27 May 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 108 times and liked it 3 visitors.