简体   繁体   中英

How delete a property of Object without “delete” operation

I need to delete the property of Object. Given an "id" , I must delete value[id] . I try this code:

delete value[id];

But the delete operator deletes only a reference, never an object itself.Anyone can suggest me any methods to delete forever a objects property?

JavaScript doesn't allow you to do such a thing, it is garbage collected, this means you have no direct control over what happens in memory. You can only delete a reference. Make sure you delete it anywhere else it is used if you want it gone forever.

FROM Mozilla

go through the link, it explains it properly..

Main points from the link is added below..

Unlike what common belief suggests, the delete operator has nothing to do with directly freeing memory (it only does indirectly via breaking references. See the memory management page for more details).

If the delete operator succeeds, it removes the property from the object entirely. However, if a property with the same name exists on the object's prototype chain, the object will inherit that property from the prototype.

delete is only effective on an object's properties. It has no effect on variable or function names. While sometimes mis-characterized as global variables, assignments that don't specify an object (eg x = 5) are actually property assignments on the global object.

delete can't remove certain properties of predefined objects (like Object, Array, Math etc). These are described in ECMAScript 5 and later as non-configurable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM