FOR JAVASCRIPT:
- Shallow Copy:
object2 = object1
- Deep Copy:
object2 = {...object1} //for arrays: array2 = [...array1]
- Deep Copy (for Objects with nested Objects):
object2 = JSON.parse(JSON.stringify(object1));
- Deep Copy (for objects with nested 'Date object' OR functions):
1- npm i loadash
2- const _ = require('loadash');
3- object2 = _.cloneDeep(object1);