JS: Reflect.deleteProperty

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

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);

JavaScript. Access Properties