DEV Community

Sk
Sk

Posted on

1 1

Easily delete Object Properties in JS with this Meta trick πŸ”₯πŸ”₯

why?

Reflect.deleteProperty(Object, key)

first it's metaprogramming and sounds way cooler than delete, on a serious note sometimes the delete keyword does not work as intended i don't know why, i was working on a cormmecial project recently and had may objects and nested objects, delete failed to delete the keys while deleting the value, and Reflect came to the rescue, it is built in and more efficient.

let ob = {name: "Sk", age: 22}
Reflect.deleteProperty(ob, "name")
//->  { age: 22 }


Enter fullscreen mode Exit fullscreen mode

Honestly Reflect.deleteProperty shines in nested objects

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

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

Okay