offline version v3


12 of 264 menu

delete operator

The delete operator removes a property from an object. After removal, this property will have an undefined value.

Syntax

delete object.property;

Example

Let's create an object and remove one of its properties from it:

let obj = { name: 'john', age: 23, }; delete user.name; console.log(user.name);

The code execution result:

undefined

Example

Let's create an array and remove an element from it:

let arr = ['a', 'b', 'c', 'd']; delete arr[2]; console.log(arr);

The code execution result:

['a', 'b', empty, 'd']

See also

  • the push and unshift methods
    that add elements to an array
  • the splice method
    that also cuts off array parts, while modifying the array itself
  • the in operator
    that checks if an object or array has a property
enru