Home » JavaScript

delete Operator with Example in JavaScript

JavaScript delete Operator: Here, we are going to learn what delete operator in JavaScript is and how it is used?
Submitted by IncludeHelp, on February 01, 2019

JavaScript delete Operator

"delete" is an operator in JavaScript and it is used to delete a property of an object. After deleting the particular property, that property will not be accessible and returns "undefined".

Syntax:

delete property;

Example:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>		
		var employee = {
			name: "Amit shukla",
			age: 21,
			city: "Gwalior",
			Country: "India"
		};
		
		//printing the object
		document.write("Printing employee details...<br>");
		document.write("Name: " + employee.name + "<br/>");
		document.write("Age: " + employee.age + "<br/>");
		document.write("City: " + employee.city + "<br/>");
		document.write("Country: " + employee.Country + "<br/>");
		document.write("<br>");
		
		//deleting properties age & city
		delete employee.age;
		delete employee.city;

		document.write("Printing employee details after delete...<br>");
		document.write("Name: " + employee.name + "<br/>");
		document.write("Age: " + employee.age + "<br/>");
		document.write("City: " + employee.city + "<br/>");
		document.write("Country: " + employee.Country + "<br/>");		
	</script>
</body>
</html>

Output

Printing employee details...
Name: Amit shukla
Age: 21
City: Gwalior
Country: India

Printing employee details after delete...
Name: Amit shukla
Age: undefined
City: undefined
Country: India





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.