delete

Removes a property from an object.

Since ES1 Spec ↗

Syntax

delete object.prop
delete object[key]

Returns

boolean — `true` if the property was deleted or did not exist; `false` if the property is non-configurable.

Examples

const obj = { a: 1, b: 2 };
delete obj.a;
console.log(obj);
Output
{ b: 2 }
const obj = { x: 1 };
console.log(delete obj.x);
console.log(delete obj.missing);
Output
true
true
const arr = [1, 2, 3];
delete arr[1];
console.log(arr);
console.log(arr.length);
Output
[ 1, <1 empty item>, 3 ]
3

Notes

- Deleting an array element leaves a hole; it does not reindex or change `length`. Use `splice()` to remove elements. - `delete` only removes own properties, not inherited ones. - It cannot delete variables or non-configurable properties.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also