Javascript: Deleting object properties

From MapbenderWiki

Jump to: navigation, search

Assume there is an object

var someObject = {
    "property1":"value1",
    "property2":"value2"
};

If we want to remove the property "property1" to receive this

{
    "property2":"value2"
};

just type

delete someObject.property1;


REMEMBER: if the property name is in a variable

var propertyName = "property1";

you need to use the bracket syntax

delete someObject[propertyName];
Personal tools