![]() |
VOOZH | about |
The Lodash _.cloneDeep() method is handy for making a complete copy of a value. It goes deep into the value, copying everything inside it too. So, the new object you get has the exact same data as the original, but they're not linked in memory.
This method is similar to the _.clone() method.
_.cloneDeep(value);Example 1: In this example, It is returning false because they both have the same value but different memory allocations, and the "===" operator checks for the same reference in objects
Output:
Comparing original with deep false
After changing original value
Original value { x: 10 }
Deep Copy value { x: 23 }
Example 2: In this example, It is returning false because they both have the same value but different memory allocations, and "===" operator checks for the same reference in objects and we can change the original object it will not change the cloned object's value as both of them have different memory allocation
Output:
Comparing original with deep false
After changing original value
Original value [ { x: 10 }, { y: 2 } ]
Deep Copy value [ { x: 1 }, { y: 2 } ]