我的数组:
[
{
name: 'test1',
state: 'OK',
status: true,
pending: 33,
approved: 0,
active: 0,
inactive: 33
},
{
name: 'test3',
state: 'OK',
status: true,
pending: 33,
approved: 0,
active: 0,
inactive: 33
},
{
name: 'test4',
state: 'OK',
status: true
}
]
如果对象中不存在“pending”,“approved”,“active”和“inactive”键,则需要输出以下内容:
期望输出:
[
{
name: 'test1',
state: 'OK',
status: true,
pending: 33,
approved: 0,
active: 0,
inactive: 33
},
{
name: 'test3',
state: 'OK',
status: true,
pending: 33,
approved: 0,
active: 0,
inactive: 33
},
{
name: 'test4',
state: 'OK',
status: true,
pending: 0,
approved: 0,
active: 0,
inactive: 0
}
]
如何完成这个任务?
我尝试使用map,但是不知道如何设置条件。
我想将所有的值都设为零。