多重数组过滤

时间:2022-12-30 23:30: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);