title: How do I retrieve a list of active items from an Array?
body: <p>I'm trying to get a list of employees who only have active hobbies and whose role is of type 'A'.</p>
  
  <p>I tried using the below query but without any success.</p>
  
  <p>What am I doing wrong?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Get all the employees with active hobbies and have a role of 'A'
  var employees = people.find(item =&gt; item.key === 'Employees').employees.map(emp =&gt; emp.hobbies).filter(hobby =&gt; hobby.filter(h =&gt; h.active === true &amp;&amp; h.roles.includes('A')));
  
  console.log(employees);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script&gt;
    var people = [{
      key: 'Employees',
      employees: [{
          name: 'joe',
          age: 20,
          hobbies: [{
            'active': true,
            name: 'skating',
            roles: ['C', 'A']
          }]
        },
        {
          name: 'amy',
          age: 32,
          hobbies: [{
            'active': true,
            name: 'surfing',
            roles: ['A']
          }]
        },
        {
          name: 'kate',
          age: 34,
          hobbies: [{
            'active': true,
            name: 'running',
            roles: ['C']
          }, {
            name: 'Chess',
            active: false,
            roles: ['C', 'A']
          }]
        }
      ]
    }];
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Update</strong></p>
  
  <p>When I added more employees with new hobbies to the array, the accepted answer fails to produce the correct output. Why does this happen?</p>
  
  <pre><code>var people = [{
          key: 'Employees',
          employees: [{
                  name: 'Steve',
                  age: 50,
                  hobbies: [{
                          active: true,
                          name: 'skating',
                          roles: ['C', 'A']
                      },
                      {
                          active: false,
                          name: 'skating',
                          roles: ['C', 'A']
                      },
                      {
                          active: true,
                          name: 'snooker',
                          roles: ['C', 'A']
                      },
                      {
                          active: true,
                          name: 'darts',
                          roles: ['C', 'A']
                      }
                  ]
              },{
                  name: 'joe',
                  age: 20,
                  hobbies: [{
                          active: true,
                          name: 'skating',
                          roles: ['C', 'A']
                      }
                  ]
              }, {
                  name: 'amy',
                  age: 32,
                  hobbies: [{
                          'active': true,
                          name: 'surfing',
                          roles: ['A']
                      }
                  ]
              }, {
                  name: 'kate',
                  age: 34,
                  hobbies: [{
                          active: true,
                          name: 'running',
                          roles: ['C']
                      }, {
                          name: 'Chess',
                          active: false,
                          roles: ['C', 'A']
                      }
                  ]
              }
          ]
      }
  ];
  
  var employees = people.find(item =&gt; item.key === 'Employees').employees.filter(employee =&gt; employee.hobbies.every(h =&gt; h.active &amp;&amp; h.roles.includes('A')));
  </code></pre>