JavaScript: Reflect.deleteProperty

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.deleteProperty(obj, key)
Deletes the property key from obj.

Return true if

  • key exist and is deleted
  • key does not exist

else false.

This function is similar to the syntax “delete” Operator, but in a function form. Function form lets you easily manipulate it at run-time.

Reflect.deleteProperty also has more strict return value.

const jj = { kk: 1 };
Reflect.deleteProperty(jj, "kk");
console.log(jj.hasOwnProperty("kk") === false);
/* [ example when key doesn't exist ] */
const jj = { kk: 1 };
console.log(Reflect.deleteProperty(jj, "y") === true);
/* [ example when deleting failed ] */
const jj = { kk: 1 };
Object.freeze(jj);
console.log(Reflect.deleteProperty(jj, "kk") === false);

Delete Property

BUY ΣJS JavaScript in Depth