How do I remove a property from a JavaScript object?

JavascriptWeb DevelopmentFront End Technology

To remove a property from a JavaScript object, use the delete keyword. You can try to run the following code to learn how to remove a property

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p id="demo"></p>
      <script>
         var cricketer = {
            name:"Amit",
            rank:1,
            points: 150
         };
         delete cricketer.rank;
         document.getElementById("demo").innerHTML =
            cricketer.name + " has " + cricketer.rank + " rank.";
      </script>
   </body>
</html>
raja
Published on 02-Jan-2018 12:48:21
Advertisements