To remove a property from a JavaScript object, you can use the delete operator.
For example:
let obj = {
foo: "bar",
baz: 42
};
delete obj.foo;
console.log(obj); // { baz: 42 }
Keep in mind that the delete operator only removes the property from the object. It does not delete the value of the property.
For example:
let obj = {
foo: "bar",
baz: 42
};
let foo = obj.foo;
delete obj.foo;
console.log(foo); // "bar"
In this example, the delete operator removed the foo property from the obj object, but the value of the foo property ("bar") is still being stored in the foo variable.
Comments (0)