Delete Icon

How to remove a property from a javascript object

Add this to the “I-can’t-believe-I-didn’t-know-this” bucket.

If you have a javascript object that looks like this:

var myObj = { propA : "aaaa", propB : "bbbbb" };

and you need to remove all reference to propA (not just make it null), you could use the following javascript:

delete myObj.propA

which will erase propA entirely from myObj, which would then look like:

{ propB : "bbbbb" }


Leave a Reply

Your email address will not be published. Required fields are marked *