Test name | Executions per second |
---|---|
Lodash cloneDeep | 163739.6 Ops/sec |
Json clone | 198367.1 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var MyObject = {
string: 'Creates a deep copy of source, which should be an object or an array.',
number: 1234567890,
boolean: true,
nullable: null,
json: {
stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
parse: 'JSON.parse() method parses a JSON string...'
},
array: [
{
id: 5,
blocked: false,
avatar: null,
user: {
firstName: 'Alan',
lastName: 'Walker'
},
},
{
id: 5688,
blocked: false,
avatar: null,
user: {
firstName: 'Anna',
lastName: 'Wanderwood'
},
},
{
id: 80043,
blocked: true,
avatar: 'image.jpg',
user: {
firstName: 'Serj',
lastName: 'Cooper'
},
},
]
};
var myCopy = null;
myCopy = _.cloneDeep(MyObject);
myCopy = JSON.parse(JSON.stringify(MyObject));