JS Built-ins
← Proxy21 / 100
ProxydeletePropertyintermediate

Proxy deleteProperty trap β€” log deleted key

πŸ“– Usage Example
const log = []
const p = new Proxy({}, {
  deleteProperty: (t, k) => { log.push(k); return true }
})
delete p.foo
console.log(log) // β†’ ['foo']

The deleteProperty trap intercepts delete operations, allowing custom logic when a property is deleted from a proxy.

Proxy deleteProperty trap

The deleteProperty trap intercepts the delete operator. Use it to observe or prevent deletions.

Challenge: Verify that delete p.x pushes 'x' into a deleted array.

πŸ’‘ Hints (1)
  • β€’ The `deleteProperty(target, key)` trap is called when `delete proxy.key` is executed.