猿问

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

我有一个由对象组成的数组。这是一个例子:


[

{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'})

    });

返回空数组。


天涯尽头无女友
浏览 283回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答