title: Validating if object data is "true" and retrieving relevant data if so
body: <p>I have a problem to solve using some data from an object. The data could take a few forms and may or may not exist in the first place. For example</p>
  
  <pre><code>things : {
     oranges: true,
     apples : false
  }
  </code></pre>
  
  <p>but it could equally be: </p>
  
  <pre><code>things : {
     oranges: false,
     apples : false
  }
  </code></pre>
  
  <p>or maybe <code>things</code> doesn't even exist</p>
  
  <p>I need to:</p>
  
  <p>1) Determine that <code>things</code> exists</p>
  
  <p>2) Determine that <code>things</code> contains further keys</p>
  
  <p>These two statements need to be verified in one callable function e.g <code>thingsHasData()</code></p>
  
  <p>3) If <code>things</code> does have data, is any of the data set to <code>true</code>?</p>
  
  <p>This also needs to be a callable function e.g <code>fruitsIsTrue()</code></p>
  
  <p>4) Return the key for one of the true values</p>
  
  <p><code>trueFruit()</code> - this should only return one key, but it doesn't matter which <em>(it shouldn't ever have two true values as per business rules but it's more of a fallback to just return one if for some reason it does)</em></p>
  
  <p>So I've been able to get the key of a <code>true</code> key-value pair using the following:</p>
  
  <pre><code>var thingsList = {
      things : {
             oranges: false,
             apples : true
          }
      }
  var trueFruit = Object.keys(thingsList).filter(function(key) {
      return thingsList[key];
  });
  
  return thingsList[0];
  </code></pre>
  
  <p>This correctly returns <code>apples</code> and only apples so it works for point <em>4</em> but not the others, and I feel like there is a better way to do this not having to rely on repeating the same <code>.filter</code> in a few different functions. Ideas?</p>