为了账号安全,请及时绑定邮箱和手机立即绑定

过滤掉对象中未定义的属性

过滤掉对象中未定义的属性

天涯尽头无女友 2021-10-21 14:12:02
我有一个由对象组成的数组。这是一个例子:[{events: Array(5), conditions: {…}},{events: Array(5), conditions: {…}}{conditions: {…}, awaits: Array(0), events: Array(1), pid: "123"}] 如您所见,对象有所不同。有些具有属性“pid”,有些则没有。这就是这个问题的全部内容。我想将带有 pid 的那些分配给一个包含 pid 的对象的新数组。假设这个数组存储在 match.entries 中。嗯,这就是我尝试过的。// aa = match.entries.filter(entry => {return typeof entry.pid !== 'undefined'})这似乎不起作用。我的整个代码:    let aa = [];   conditionalMatches.forEach(match => {      aa = match.entries.filter(entry => {return typeof entry.pid !== 'undefined'})    });返回空数组。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 282 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信