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.

Reflect.deleteProperty is similar to the Delete operator but with more strict return value and in a function form.

const obj = {x: 1};
Reflect.deleteProperty ( obj , "x" );
console.log( obj.hasOwnProperty("x") === false ); // true

Example when key doesn't exist:

const obj = {x: 1};

console.log(
Reflect.deleteProperty ( obj , "y" )
); // true

Example when deleting failed:

const u = {p: 1};
Object.freeze ( u );

console.log(
Reflect.deleteProperty ( u , "p" ) === false
); // true

[see Access Property]

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Reflect