DEV Community

Discussion on: Four Ways to Clone Array with Ease! Easiest Method to Clone Array.

Collapse
z00md profile image
z00md

Just remember that all these methods just get you a new array with copied values for single level only. For any nested objects or multi dimensional arrays you need to access each and every value and copy it by yourself.

Collapse
hasnaindev profile image
Muhammad Hasnain Author

Thanks for pointing that out. The idea is to know how to clone a single array. When it comes to nesting, same rules or methods apply. However, it is much better to use an npm package to clone deep and nested objects recursively. Thank you.