0

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.

static660
  • 81
  • 1
  • 13
  • Looks like a solution looking for a problem to me. Why not just use the "similar" object and let the garbage collector reclaim the old one? As for efficiency, reading an object from a database is vastly more costly than a deep-copy, whatever method you might use. – kuroi neko Jun 02 '18 at 11:13
  • I understand this , but it is essential for what I am going. Thanks for the input :) – static660 Jun 02 '18 at 16:22

0 Answers0