如何从 JavaScript 对象中删除项目

2022-08-29 23:18:55

如何从 JavaScript 对象中删除项目?

喜欢这个:

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

答案 1

var test = {'red':'#FF0000', 'blue':'#0000FF'};
delete test.blue; // or use => delete test['blue'];
console.log(test);

这将删除测试.blue


答案 2