标签云

微信群

扫码加入我们

WeChat QR Code

如何从一个JavaScript对象[复制]删除项目

Possible Duplicate:
How to remove a property from a javascript object

How can I remove an item from a JavaScript object?

Like this:

var test = {'red':'#FF0000', 'blue':'#0000FF'};
test.remove('blue');


I believe this is the solution How to remove a property from a javascript object

2018年05月27日27分48秒

This works great, you can check it here live: jsfiddle.net/b8whD/2

2018年05月27日27分48秒

I haven't gotten a capcha right the first time in years. Really makes you think...

2018年05月27日27分48秒

Hotgeart but delete test[0] will succeed. Although, if you are using naturally incrementing integers for your object keys maybe consider an array?

2018年05月27日27分48秒

Kermani No, delete has existed since ES1. See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

2018年05月27日27分48秒

PatrickFinnigan It is funny, because I did not expect to see any easy good from ES1 :)

2018年05月27日27分48秒