javascript delete operator code example

Example 1: javascript delete key from object

let person = {
  firstname: 'John',
  lastname: 'Doe'
}

console.log(person.firstname);
// expected output: "John"

delete person.firstname;

console.log(person.firstname);
// expected output: undefined

Example 2: what is the function of delete operator in javascript

var student= {age:20, batch:"ABC"};
delete student.age;

Example 3: nodejs delete object key

delete obj.firstname;

Example 4: js Property Assignment delete

delete objectName['Property Name'];
delete objectName.propName;