答案 0 :(得分:1)
var a = {name: 'pardeep', 'sirname': 'jain'}
delete a['name']
console.log(a);
只需将delete
关键字用作这样的键-
delete objectName['keyName']
答案 1 :(得分:0)
const deleteAttribute = (array, attribute) => array.map(x => {
// Delete the attribute here
delete x[attribute];
return x;
});
const arr = [{
attr: 'hello',
color: 'red',
organization: 'Good'
}, {
attr: 'world',
color: 'blue',
organization: 'bad'
}];
console.log(deleteAttribute(arr, 'organization'));
答案 2 :(得分:0)
您可以像下面一样使用map
和delete
var arr = [{
name: 'hi',
test: 'x',
organization: 'X'
}, {
name: 'guys',
test: 'y',
organization: 'Y'
}];
console.log(arr.map(x => { delete x.organization; return x}));