How to Deep Copy Objects or Arrays in JavaScript

preview_player
Показать описание
In today's video I'll be taking you through one of the best ways to perform a
deep clone (copy) or an array or object in JavaScript. This uses a recent function addition called "structuredClone()".

Please be way about browser compatibility which you can find down below 👇

For your reference, check this out:

THE ULTIMATE JAVASCRIPT DOM CRASH COURSE 👇

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

*3 OTHER WAYS TO COPY OBJECTS IN JAVASCRIPT:*

*THE ULTIMATE JAVASCRIPT DOM CRASH COURSE* 👇

dcode-software
Автор

I remember coming across this problem as a young developer many years ago when the web was newish (with not much support online) and been super confused as to what was going on, I think I ended up writing a function to deep copy the object.. now as a casual node dev this video is a great refresher, as your other videos..

RossBobby
Автор

I discovered this while reading the documentation for web workers and I didn't get why this wasn't a public api, but it's nice to know that's changed now

Daniel_WR_Hart
Автор

Wow ! just in time as i was reading up on deep and shallow copy the video popped out

kennzuki
Автор

in my commuting time, I have been watched your channel everyday on the subway. thank you so much. your video is very helpful to me.

s유아마에브리띵
Автор

Thankyou very much, it was very easier to understand deep copy

rajattripathi
Автор

It this function work for object methods also?

stevejisha
Автор

Thank you very much for the explanation. It's such a shame JS is so counter intuitive in this matter... Well, there's no perfect language

MegaZeeeh
Автор

Hi mate,
Thanks for the content.
I´ve got this error message while using structuredClone: "ReferenceError: structuredClone is not defined"
How to tackle it ? Thanks in advance.

centralbiz
Автор

hi dcode can you do auto indent inside contenteditable?

pineapplecodebeginner
Автор

Great tutorial!
I don't understand why it's false when you didn't even modify the original object yet. I understand that it's false when you add the 4th element to the array, but why is it false before? They're not the same, but they're identical

frankdrolet
Автор

why you dont just stringyfy the object and then parse it??? i tried it and the copy wasnt a reference anymore.

bilal
Автор

A HUGE DISLIKE. ADD GET METHOD TO AN OBJECT AND YOU'LL SEE

tnsaturday