How to remove a property from a JavaScript object

JavascriptWeb DevelopmentFront End Technology

The delete keyword is used to remove the property and also the value of the property. After deletion, the property cannot be used before it is added back again.

In your example it can be used as -

Example

<html>
<body>
<p id="demo"></p>
<script>
var cricketer = {
   name:"John",
   rank:3,
   points: 800
};
delete cricketer.points;
document.getElementById("demo").innerHTML =
cricketer.name + " scored" + ' '+cricketer.points
</script>
</body>
</html>

Output

John scored undefined
raja
Published on 27-Sep-2018 17:43:47
Advertisements