JavaScript에서 delete 속성을 사용하여 개체에서 속성을 제거합니다. 다음 코드를 실행하여 삭제 연산자로 작업하는 방법을 배울 수 있습니다. 여기서 책값을 삭제합니다 -
예시
<html>
<head>
<title>JavaScript Delete Operator</title>
<script>
function book(title, author) {
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script>
var myBook = new book("WordPress Development", "Amit");
book.prototype.price = null;
myBook.price = 500;
document.write("<h2>Details before deleting book price</h2>");
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price);
delete myBook.price;
document.write("<br><h2>Details after deleting book price</h2>");
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price + "<br>");
</script>
</body>
</html>