3 回答

TA贡献1911条经验 获得超7个赞
你可以这样
item = { a: 'A', b: 'B', circularProperty: 'abc' };
function removeProperty(obj, propertyName) {
let { [propertyName]: _, ...result } = obj
return result
}
console.log(removeProperty(item, 'circularProperty'));

TA贡献1155条经验 获得超0个赞
使用delete和临时变量
const item = {
a: 'A',
b: 'B',
circularProperty: {
a: 'A',
b: 'B',
circularProperty: {
a: 'A',
b: 'B'
}
}
};
let temp = item.circularProperty;
delete item.circularProperty;
console.log(item);
item.circularProperty = temp;
console.log(item);

TA贡献1873条经验 获得超9个赞
我知道lodashpick如果我没有记错的话,就有一种方法,但是我不相信jQuery为此内置了操作。您可能必须重建对象。
var objectKeys = Object.keys(item);
var keysWithoutCircularProperty = objectKeys.filter(function(key){
return key != 'circularProperty';
});
var shallowClone = keysWithoutCircularProperty.reduce(function(result, key) {
result[key] = item[key];
return result;
}, {});
删除了箭头功能,因为您在另一个答案中没有说ES6。
添加回答
举报