var prodId = 22;

var relatProdId = 109;

var posts = [
    { name: "Luigi",
      categories: [22,109,33,11]
    },
  {name: "Mario",
   categories: [22,11,3243,1]
  },
   {name: "Chiara",
    categories: [10,109,11]
   },
   {name: "Max",
    categories: [22,12,33,11]
   },
   {name: "Gianni",
    categories: [22,33,11]
   },
   {name: "Sara",
    categories: [22,109]
   },
   {name: "Giulia",
    categories: [22,13,17]
   },
   {name: "Elon",
    categories: [22,12,109,11]
   }
  
];
var result = posts.filter(function(e) { return (e.categories.indexOf(prodId) >= 0) && (e.categories.indexOf(relatProdId) >= 0) });
console.log(result);
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.