Most efficient way to update a already existing object(with a similar one)

38 views Asked by At

What's up guys , I have a problem with atomics and this is where I'm at : I need to find the " most efficient way to alter one object with another.

Let's say I have object1 and I have object2 they are both identical in the fact they share the same Id , name.....ect but let's say that object is deprecated and object2 is read from a server or a database .

Would it A: be cheaper to just deep clone with Object.assign ().

A.1: to use the object grabbed to replace the already existing one (a=b) .

B:to loop through the enumerable properties of object2 (obj1.propA = obj2.propA).

I am wondering what is the most effective way to work with thousands of objects . I usually try to avoid loops and definitely double loops.

     let object1 = {
  a: 1,
  b: 2,
  c: 3
};

object1 = Object.assign({c: 4, d: 5}, object1);

console.log(object1.c, object1.d);
// expected output: 3 5

I've tried the code here and it works but I have zero idea if it is the most efficient model.

0

There are 0 answers