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!
Смотрите видео What's the Best Way to Copy/Clone an Array in JavaScript? (comparison) онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Apes in Capes 27 Май 2022. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 108 раз и оно понравилось 3 посетителям.