Scroll Down
How to do a shallow or deep clone of an Javascript Object using JS ES5, JS ES6 or Lodash. Please note that in the shallow copy the nested properties are just copied by reference.
Be aware that you can’t use JSON.stringify to clone Functions and that Date objects will be stringified in the process.
var clone = JSON.parse(JSON.stringify(obj));
var clone = _.cloneDeep(obj, true);
const clone = Object.assign({}, obj);
const clone = {...obj};
var clone = _.clone(obj, true);
For benchmarking I’ve used this JSPERF test setup.