DEV Community

Mohamed Idris
Mohamed Idris

Posted on

Things I learned recently...

  • const obj1 = obj2;

obj1 is now a reference for obj2, it just pointing to obj2. So, modifying obj2 will also modify obj1

If you want to be able to modify obj1 freely, a simple solution is by destructuring:

const obj1 = {...obj2};


  • const obj3 = {a: 2, b: 3, c: 4}, and you want to exclude or delete the 'b' attribute? :

delete obj3['b'];


  • Destructing with an alias!

const obj4 = {name: "Idris"};

if we want to set the name attribute to a new variable called username, we can do it like this:

const {name: username} = obj4;

console.log(username); // Idris

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay