多重数组过滤

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);

猜你喜欢

转载自www.cnblogs.com/y896926473/p/9338202.html