JavaScript handler.deleteProperty() Method - JavaScript Tutorial

JavaScript handler.deleteProperty() Method

BLUF: This tutorial on JavaScript handler.deleteProperty() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript handler.deleteProperty() Method

Understanding JavaScript handler.deleteProperty() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The handler.deleteProperty function is utilized to completely eliminate a property by employing the delete operator. This function yields a true value if the deletion was accomplished successfully.

Syntax

Example

deleteProperty: function(target, property)

Parameters

Target : The target object.

Property : The name of the property to delete.

Return value

This procedure yields a Boolean result. It signifies whether the property has been successfully deleted or if the deletion has failed.

Browser Support

Chrome 49
Edge 12
Firefox 18
Opera 36

Example 1

Example

var proxy = new Proxy({}, {

  deleteProperty: function(target, prop) {

    document.writeln("Called: " + prop);

    return true;

    //if sucessfullt delete,return true.

  }

});delete proxy.abc;

Output:

Output

Called: abc

Example 2

Example

var proxy = new Proxy({}, {

  deleteProperty: function(target, name) {

    document.write('In delete Property  ');

 

    return delete target[name];

  }

});

delete proxy.foo;

document.writeln(proxy.name);

Output:

Output

In delete Property undefined

Example 3

Example

var f = { bar: 'baz' }

f.bar = 'baz'

document.writeln('bar' in f)



delete f.bar

document.writeln('bar' in f)



var foo = { bar: 'baz' }

foo.bar = 'baz'

document.writeln('bar' in foo)

Output:

Output

true false true

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience