我有以下对象:
var myArr = {one:'1',two:'2',three:'3',four:'4',five:'5'};
delete myArr[one,three,five];
delete myArr[one]; delete myArr[three]; delete myArr[five];
谢谢.
解决方法
您可以使用数组作为键并迭代进行删除.
var object = { one: '1',two: '2',three: '3',four: '4',five: '5' }; ['one','three','five'].forEach(function (k) { delete object[k]; }); console.log(object);
var object = { one: '1','five'].forEach(Reflect.deleteProperty.bind(null,object)); console.log(object);