Algorithm
-
Input: Take the object and the property to be removed as input.
-
Check Property Existence: Verify if the object has the specified property. If the property exists, proceed; otherwise, the operation is complete.
-
Remove Property: Delete the specified property from the object. In JavaScript, you can use the
delete
operator for this purpose. -
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
age: 20,
hobbies: ["reading", "games",
"coding"],
name: "Akash"
}
Demonstration
JavaScript Programing Example to Remove a Property from an Object-DevsEnv