The Reflect.deleteProperty function provides the capability to remove a property from an object. A return value of true indicates that the property was successfully deleted. Conversely, if it returns false, the deletion was unsuccessful.
Syntax:
Example
Reflect.deleteProperty(target, propertyKey)
Parameters:
target: This refers to the object that serves as the target for removing the specified property.
propertyKey: This refers to the identifier of the property that is intended for removal.
Return value:
A Boolean indicates whether the deletion of the property was successful or not.
Exceptions:
A TypeError, if the target is not an Object.
Browser Support:
| Chrome | 49 |
|---|---|
Edge |
12 |
| Firefox | 42 |
| Opera | 36 |
Example 1
Example
var array1 = [1, 2, 3, 4, 5];
Reflect.deleteProperty(array1, '3');
document.writeln (array1);
Output:
Output
1,2,3,,5
Example 2
Example
const obj = {a: 1};
Object.freeze (obj );
document.writeln ( Reflect.deleteProperty ( obj , "a" ) );
Output:
Example 3
Example
const obj = {a: 1, b:6, c:5};
document.writeln ( Reflect.deleteProperty ( obj , "a" ) );
document.writeln ( Reflect.deleteProperty ( obj , "b" ) );
document.writeln ( Reflect.deleteProperty ( obj , "c" ) );
Output:
Output
true true true