- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete a setter using the delete operator in JavaScript?
To delete a setter using the delete operator, use the delete keyword. Here’s how you can delete −
delete obj.name
Example
You can try to run the following code to learn how to delete a setter
<html> <body> <script> var department = { deptName: "Marketing", deptZone: "North", deptID: 101, get details() { return "Department Details<br>" + "Name: " + this.deptName + " <br>Zone: " + this.deptZone + "<br>ID: " + this.deptID; }, set details(info) { var res = info.toString().split(' '); this.deptName = res[0] || ''; this.deptZone = res[1] || ''; this.deptID = res[2] || ''; } } department.details = 'Marketing North 001'; document.write("<br>Department Name: " + department.deptName); document.write("<br>Departmet Zone: " + department.deptZone); document.write("<br>Department ID: " + department.deptID); delete department.deptName; document.write("<br>Department Name (after deletion): " + department.deptName); </script> </body> </html>
Advertisements