有一个对象,需要筛选掉他的某些属性
const obj = {
a: 1,
b: 2,
c: 3,
d: 5,
};
const deleteKeys = ["b", "c"];
function filterObjKeys(obj, keys) {
return Object.keys(obj).reduce((newData, key) => {
if (!keys.includes(key)) {
newData[key] = obj[key];
}
return newData;
}, {});
}
const newObj = filterObjKeys(obj, deleteKeys);
console.log(newObj); //{ a: 1, d: 5 }