Angular 2从对象数组中删除值

时间:2018-10-29 19:56:11

标签: javascript angular typescript

我有1个包含对象的数组:

one = [
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'}
]

我想从所有帐户中删除key,该怎么做?

2 个答案:

答案 0 :(得分:3)

一种方法是遍历并删除属性

one.forEach(o => delete o.key);

答案 1 :(得分:2)

您可以执行以下操作

const one = [
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'},
    {name: 'Name', key: '4868466'},
]

const result = one.map((item) => {
 delete item.key
 return item
})

console.log("result:", result)