如何从Array对象中删除键+值对 [英] How to remove key+value pair from an object of Array
本文介绍了如何从Array对象中删除键+值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从所有对象中删除属性'b'
如何删除???
I want to remove property 'b' from all objects how i remove???
let result=[
{
'id':'1',
'b':'asd'
},
{
'id':'2',
'b':'asd'
},
...
,
{
'id':'2000',
'b':'asd'
},
]
// delete object.b; its only for object and want to remove from whole
// array 2000 records
使用foreach循环是从对象数组中删除键+值对的正确方法
Using foreach loop is it correct way to delete key + value pair from array of objects
推荐答案
如果那个是你拥有的唯一结构可以这样做
if that one is the only structure you have you can do this
result = result.map(e => ({ id: e.id }))
或者如果结构复杂得多,你可能想要使用 delete
:
or if the structure is far more complicated, you might want to use delete
:
result.forEach((e) => {
delete e.b;
});
这篇关于如何从Array对象中删除键+值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文