首页 > 技术文章 > 多重数组过滤

y896926473 2018-07-19 20:29 原文

const results=[{"product_id":1,"title":"booking","draft":!1,"publish":!0,"category":[{"cat_id":1,"cat_name":"web","product":"booking"}],},{"product_id":2,"title":"reading","draft":!1,"publish":!0,"category":[{"cat_id":6,"cat_name":"android","product":"asdasd"}],},{"product_id":3,"title":"reading","draft":!1,"publish":!0,"category":[],},];
const filtered = results.filter(
  ({ category }) => category.some(({ cat_id }) => cat_id === 1)
);
console.log(filtered);

 

推荐阅读