Skip to content
Related Articles

Related Articles

JavaScript | Reflect.deleteProperty() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 30 Jun, 2022

The Reflect.deleteProperty() method in JavaScript is used to delete a property on an object. It returns a Boolean value which indicates whether the property was successfully deleted.
Syntax: 
 

Reflect.deleteProperty( target, propertyKey )

Parameters: This method accept two parameters as mentioned above and described below: 
 

  • target: This parameter delete the property and it is the target object.
  • propertyKey: This parameter is name of the property which is to be deleted.

Return Value: This method returns a Boolean value which indicates whether the property was successfully deleted.
Exceptions: A TypeError is exception given as the result, when the target is not constructor.
Example 1: 
 

javascript




const object1 = {
  property1: 76
};
 
Reflect.deleteProperty(object1, 'property1');
 
console.log(object1.property1);
 
const array1 = [1, 2, 3, 4, 5];
Reflect.deleteProperty(array1, '12');
console.log(array1);
 
Reflect.deleteProperty(array1, '1');
console.log(array1);
 
Reflect.deleteProperty(array1, '2');
console.log(array1);

Output: 
 

undefined
Array [1, 2, 3, 4, 5]
Array [1, undefined, 3, 4, 5]
Array [1, undefined, undefined, 4, 5]

Example 2: 
 

javascript




// Returns true if no such property exists
document.writeln( Reflect.deleteProperty({}, 'geeks'))
 
// Returns false if a property is unconfigurable
document.writeln( Reflect.deleteProperty(
       Object.freeze({geeks: 1}), 'geeks'))
 
const obj = {val1: 22, val2:434, val3:42}; 
const obj1 = {val:5};
document.writeln( Reflect.deleteProperty ( obj, "val1" ) ); 
document.writeln( Reflect.deleteProperty ( obj, "val2" ) );  

Output: 
 

true false true true

Supported Browsers: The browsers supported by Reflect.deleteProperty() method are listed below: 
 

  • Google Chrome 49 and above
  • Edge 12 and above
  • Firefox 42 and above
  • Opera 36 and above
  • Safar 10 and above

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!