The most efficient way to copy objects

Asked 1 years ago, Updated 1 years ago, 81 views

What is the most efficient way to copy JavaScript objects? What I've seen so far is obj = eval(uneval(o)); It's like this, but it's only available on Firefox right now. obj = JSON.parse(JSON.stringify(o)); I've seen this, but my question is the most efficient way.

clone javascript object

2022-09-21 20:20

1 Answers

// Shallow Copy 
var newObject = jQuery.extend({}, oldObject);

// a deep radiation 
var newObject = jQuery.extend(true, {}, oldObject);


2022-09-21 20:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.