Javascript 在没有任何空值的对象数组中筛选出对象

Javascript 在没有任何空值的对象数组中筛选出对象,javascript,arrays,object,Javascript,Arrays,Object,我试图过滤掉不包含任何空值的api输出——api输出(JSON)如下所示: [{ title: 'Bayern Munich defenders are scared of damned talented Jadon Sancho, says Borussia Dortmund team-mate Axel Witsel - Goal', date: '2019-08-04T11:42:00Z', image: null, description:

我试图过滤掉不包含任何空值的api输出——api输出(JSON)如下所示:

[{ title:
        'Bayern Munich defenders are scared of damned talented Jadon Sancho, says Borussia Dortmund team-mate Axel Witsel - Goal',
    date: '2019-08-04T11:42:00Z',
    image: null,
    description:
        'As Leeds kick off the new season with hopes of returning to the Premier League, we remember their painful demise from 15 years ago',
    link:
        'https://www.goal.com/en/news/even-bayern-defenders-are-scared-of-damned-talented-sancho/huf85pn3ob4s1r0fcjq52nsqe' },
    { title:
        'Manchester City y Liverpool se enfrentan con la Community Shield en juego: hora y TV - infobae',
    date: '2019-08-04T11:36:59Z',
    image:
        'https://www.infobae.com/new-resizer/ZvS6Vs3f7Qa_11HIibSiMy8DOUw=/1200x0/filters:quality(100)/s3.amazonaws.com/arc-wordpress-client-uploads/infobae-wp/wp-content/uploads/2019/08/04082112/Guardiola-Klopp.jpg',
    description:
        'El campeón y el subcampeón de la Premier League se enfrentan con el primer título de la temporada en juego. En la previa, hubo un duelo verbal entre Pep Guardiola y Jürgen Klopp. A las 11, por ESPN2',
    link:
        'https://www.infobae.com/america/deportes/futbol-europeo/2019/08/04/manchester-city-vs-liverpool-community-shield-2019/' },
    { title:
        'Ireland\'s Hourihane bangs in two stunning free-kicks ahead of Villa\'s Premier League return - The42',
    date: '2019-08-04T11:33:00Z',
    image:
        'https://img2.thejournal.ie/article/4752619/river/?height=400&version=4752623',
    description: null,
    link:
        'https://www.the42.ie/conor-hourihane-free-kicks-leipzig-4752619-Aug2019/' } ]
我目前拥有的代码实现了这一点,但它非常庞大,并且使用了大量的条件句,我希望避免使用这些条件句。这样的事情能实现吗

let filteredArr = [];
for (let i = 0; i < data.length; i++) {
    if (data[i].title !== null &&
        data[i].date !== null &&
        data[i].image !== null &&
        data[i].description !== null &&
        data[i].link !== null) {
        filteredArr.push(data[i])
    }
}

您可以通过检查所有值来筛选数组

var数据=[{标题:'拜仁慕尼黑后卫害怕该死的天才杰登·桑乔,多特蒙德队队友阿克塞尔·维塞尔说-进球',日期:'2019-08-04T11:42:00Z',图片:空,描述:'当利兹队带着重返英超的希望开始新赛季时,我们记得他们15年前痛苦的死亡',链接:'https://www.goal.com/新闻/甚至拜仁后卫都害怕该死的天才桑乔,{标题:“曼城和利物浦的社区盾:hora y TV-infobae”,日期:“2019-08-04T11:36:59Z”,图片:'https://www.infobae.com/new-resizer/ZvS6Vs3f7Qa_11HIibSiMy8DOUw=/1200x0/filters:quality(100)/s3.amazonaws.com/arc wordpress client uploads/infobae wp/wp content/uploads/2019/08/04082112/Guardiola Klopp.jpg',描述:'El campeón y El subcampeón de la Premier League se en Frenchan con El primer título de la temporada en juego.en la previa,hubo un dueloéPep Guardiola y Jürgen Klopp.A las 11,por ESPN2',链接:'https://www.infobae.com/america/remocates/futbol europeo/2019/08/04/manchester-city-vs-liverpool-community-shield-2019/'},{标题:'爱尔兰的胡里哈内在维拉的英超回归前两次惊人的任意球猛击-42',日期:'2019-08-04T11:33:00Z',图片:'https://img2.thejournal.ie/article/4752619/river/?height=400&version=4752623'说明:空,链接:'https://www.the42.ie/conor-hourihane-free-kicks-leipzig-4752619-Aug2019/' }],
结果=data.filter(o=>Object.values(o).every(v=>v!==null));
console.log(结果);

.as console wrapper{max height:100%!important;top:0;}
您可以使用筛选函数。items变量包含原始数据

const filtered = items.filter(function(item) {
  for (var key in item) {
    if (null == item[key])
      return false;
  }
  return true;
});
const filtered = items.filter(function(item) {
  for (var key in item) {
    if (null == item[key])
      return false;
  }
  return true;
});