JSFiddle - React, Tailwind, and code Playground
by henser
JavaScript
// Example JSON object
var obj = {
key1: "value1",
key2: "value2",
key3: "value3"
};
// Variable containing the key name to remove
var dynamicKey = "key2";
// Remove the key-value pair using Object.defineProperty()
Object.defineProperty(obj, dynamicKey, {
value: undefined,
writable: true,
enumerable: true,
configurable: true
});
// Output the updated JSON object
console.log(obj);