开发者

Whats the quickest way to get rid of all the properties of a an object in javascript?

开发者 https://www.devze.com 2022-12-25 15:04 出处:网络
I have an on object like so var obj = {}; function set() { obj.x1 = 20; obj.y1 = 35; obj.x2 = 60; obj.y2 = 55;

I have an on object like so

var obj = {};
function set()
{
   obj.x1 = 20;
   obj.y1 = 35;
   obj.x2 = 60;
   obj.y2 = 55;
   ...
}
开发者_如何学Go

Whats the quickest way to delete/reset all of the properties of obj?


for (p in obj) {
    if (obj.hasOwnProperty(p)) {
        delete obj[p];
    }
}

If you only have one reference to the object, then replacing it with a new one would be faster.

obj = {};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号