title: How to filter an object array of another object array in TypeScript?
body: <p>I know how to filter <code>bookings</code> by <code>b.building.id</code> here:</p>
  <pre><code>bookings.filter(b =&gt; b.building.id == this.filter.buildingId);
  </code></pre>
  <p>But how to filter the <code>bookings</code> object array if the <code>b.modules</code> is a also an array. Here's my failed attempt:</p>
  <pre><code>bookings.filter(b =&gt; b.modules.programme.facultyId == this.filter.facultyId);
  </code></pre>
  <p>And another failed attempt:</p>
  <pre><code>bookings.filter(b =&gt; {
    for (let module of b.modules) {
      module.programme.facultyId == this.filter.facultyId;
    }
  });
  </code></pre>
  <p><strong>Update:</strong></p>
  <p>Here's an example of <code>bookings</code> result in JSON:</p>
  <pre><code>[
    {
      &quot;id&quot;: 2,
      &quot;semesterId&quot;: 1,
      &quot;room&quot;: {
          &quot;capacity&quot;: 17,
          &quot;code&quot;: null,
          &quot;building&quot;: {
              &quot;id&quot;: 5,
              &quot;name&quot;: &quot;Faculty of Science&quot;
          },
          &quot;id&quot;: 15,
          &quot;name&quot;: &quot;FSB 1.10&quot;
      },
      &quot;building&quot;: {
          &quot;id&quot;: 5,
          &quot;name&quot;: &quot;Faculty of Science&quot;
      },
      &quot;bookDate&quot;: &quot;2020-11-10T00:00:00&quot;,
      &quot;timeSlots&quot;: [
          {
              &quot;id&quot;: 1,
              &quot;startTime&quot;: &quot;1900-01-01T07:50:00&quot;,
              &quot;endTime&quot;: &quot;1900-01-01T08:40:00&quot;
          },
          {
              &quot;id&quot;: 2,
              &quot;startTime&quot;: &quot;1900-01-01T08:50:00&quot;,
              &quot;endTime&quot;: &quot;1900-01-01T09:40:00&quot;
          }
      ],
      &quot;modules&quot;: [
          {
              &quot;id&quot;: 5,
              &quot;name&quot;: &quot;Computer Systems and Information Technology&quot;,
              &quot;code&quot;: &quot;SS-1202&quot;,
              &quot;lecturers&quot;: [
                  {
                      &quot;id&quot;: 4,
                      &quot;name&quot;: &quot;Lim&quot;,
                      &quot;title&quot;: &quot;Dr.&quot;
                  }
               ],
              &quot;programme&quot;: {
                  &quot;id&quot;: 1,
                  &quot;name&quot;: &quot;Computer Science&quot;,
                  &quot;shortName&quot;: null,
                  &quot;facultyId&quot;: 1
              }
          }
      ]
    }
  ]
  </code></pre>