How to remove a property from a JavaScript object?

JavascriptWeb DevelopmentObject Oriented Programming

To remove a property from a javaScript object, the code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Object Properties Example</h1>
<h2 class="sample">athlete.name</h2>
<script>
   let athlete = {
      name: "James Anderson",
      sport: "Cricket",
      trophies: "15"
   };
   document.querySelector( ".sample" ).innerHTML = `${athlete.name} who plays ${athlete.sport} has ${athlete.trophies} trophies`;
   delete athlete.trophies;
   document.querySelector( ".sample" ).innerHTML += ` <br> ${athlete.name} who plays ${athlete.sport}    has ${athlete.trophies}
   trophies`;
</script>
</body>
</html>

Output

The above code will produce the following output −

raja
Published on 08-May-2020 17:11:30
Advertisements