Algorithm


  1. Input: Take the object and the property to be removed as input.

  2. Check Property Existence: Verify if the object has the specified property. If the property exists, proceed; otherwise, the operation is complete.

  3. Remove Property: Delete the specified property from the object. In JavaScript, you can use the delete operator for this purpose.

  4. Output: Optionally, return the modified object.

 

Code Examples

#1 Code Example- Remove a Property From an Object

Code - Javascript Programming

// program to remove a property from an object

// creating an object
const student = { 
    name: 'Akash',
    age: 20,
    hobbies: ['reading', 'games', 'coding'],
    greet: function() {
        console.log('Hello everyone.');
    },
    score: {
        maths: 90,
        science: 80
    }
};

// deleting a property from an object
delete student.greet;
delete student['score'];

console.log(student);
Copy The Code & Try With Live Editor

Output

x
+
cmd
{
age: 20,
hobbies: ["reading", "games",
"coding"],
name: "Akash"
}
Advertisements

Demonstration


JavaScript Programing Example to Remove a Property from an Object-DevsEnv

Previous
JavaScript Practice Example #3 - Assign 3 Variables and Print Good Way