Array.from can be used to create a deep copy of an array. If we simple assign a value of an existing array to a new array it creates a shallow copy of the existing array.
Full stack Engineer, working hard to deliver the best quality code. Passionate about finding innovative ways to make positive social impact through technology, education and best security practices.
Full stack Engineer, working hard to deliver the best quality code. Passionate about finding innovative ways to make positive social impact through technology, education and best security practices.
For those reading this post I'll show you another interesting use for
array.from
.Try this:
Then try this:
Array.from
can be used to create a deep copy of an array. If we simple assign a value of an existing array to a new array it creates a shallow copy of the existing array.Thanks for this :). The two snippets you’ve given seem exactly the same to me - am I missing something?
Yes, you are right Charlotte, I corrected my mistake.
I just edited the second snippet, in the second line I was supposed to use
Array.from
.I hope it makes sense now.
I see! Very cool, thanks for sharing hadn't thought of that use case.