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']